1. Preface
Install Ubuntu in Windows 11 and run docker to report an error. The installation steps are as follows
Windows11 Microsoft Store installs ubuntu subsystem
Linux Ubuntu installs Docker
When using Ubuntu with WSL in Windows, an error occurs when using the systemctl command:
hh@LAPTOP-O6A604DC:~$ systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
2.Problem analysis
It may be because this Ubuntu system does not use systemd, and may use SysV init (sysvinit) to initialize the system.
You can view it with the following command:
ps -p 1
If so, the CMD column displays init, which indicates that the SysV init initialization system is used.
SysV init: If your system uses SysVinit as the init system, you can use the service command to manage and check service status. For example, to check the Docker service status, you can run:
sudo service docker status
What is Systemd?
Systemd is a set of basic building blocks for Linux systems. It provides a system and service manager that runs as PID 1 and boots the rest of the system.
systemctl, as a tool of systemd, provides interaction with services on Linux machines
3.Problem solving
3.1.Option 1:
If you still want to use systemd, enable systemd in WSL
Prerequisite: Make sure you are running WSL from Microsoft Store with version number 0.67.6 or above
Update WSL to the latest version
wsl --update
View version
wsl --version
Set WSL 2 as the default version If it is WSL1, there is also a wls.conf file by default, but the systemtcl command is not supported and must be set to WLS
wsl --set-default-version 2
Run command to view version
wsl -l -v
In the Ubuntu instance, open or add the /etc/wsl.conf file (I have already installed this here, if not, add it manually), and edit the content as follows:
[boot]
systemd=true
Then use the wsl --shutdown command to shut down the running Linux distribution.
Re-run Ubuntu.
Check the initialization information again, you can see that systemd has been used,
Run the query systemctl version, it is perfect and can be used
It has been started successfully and the query is normal
3.2.Option 2:
This error indicates that the system was not booted with systemd as the init system (PID 1). This may be because the system is using another init system (such as Upstart or SysVinit). Therefore, there is a problem when trying to use the systemctl command, since that command is systemd dependent.
If the system does not use systemd as the init system, you need to use the appropriate command for your init system to check the service status. Here are some examples of common init systems:
Upstart: If your system uses Upstart as the init system, you can use the initctl command to check the service status. For example, to check the Docker service status, you can run:
sudo initctl status docker
SysVinit: If your system uses SysVinit as the init system, you can use the service command to manage and check the service status. For example, to check the Docker service status, you can run:
sudo service docker status
The result is available and effective
Started successfully, query is normal
4. Verify that both commands can be queried and used, perfect
Government manual:
https://learn.microsoft.com/zh-cn/windows/wsl/install-manual
Reference book:
https://blog.csdn.net/B11050729/article/details/132498547
https://blog.csdn.net/m0_68736501/article/details /130289727
https://blog.csdn.net/qq_44610529/article/details/126488898
https://blog.csdn.net/weixin_41982608/article /details/132310451