The docker container reports an error when using the systemctl command

I have seen many solutions, but they are not friendly to novices and are not particularly clear

Error content:  

        System has not been booted with systemd as init system (PID 1). Can’t operate.
        Failed to connect to bus: Host is down

 

Solution:

      docker run -itd    –privileged –name myCentos centos /usr/sbin/init

      After creation: use the following command to enter the container

      docker exec -it myCentos /bin/bash

      Pay special attention to the bold content and don’t forget

      The reason is that/bin/Bash is executed in the first step by default, and systemctl cannot be used because of a bug in docker  

                      Therefore, we use/usr/SBIN/init and — privileged, so that we can use systemctl, but override the default/bin/bash

        Therefore, if we want to enter the container, we can no longer use docker attach mycentos  

        Instead, you can only use    docker exec -it myCentos /bin/bash   Because exec allows us to execute the overridden default command/bin/bash  

        At the same time -it is also necessary

        Similar to Ubuntu, the init directory may be different

Of course, I don’t know the specific bug. I hope it will be fixed in the future

 

Similar Posts: