Docker容器中使用systemctl报错

当在Dokcer容器中使用systemctl时报以下错误

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

问题原因:

启动容器时执行的启动是/bin/bash,没有相应的权限调用内核程序,需要在run修改相应的指令获得权限

解决办法

run指令后加—privileged=true,修改/bin/bash/sbin/init

1
docker run --privileged=true -itd xxxxx /sbin/init

进入容器时使用的是docker exec -it xxxxx /bin/bash

-------------本文结束感谢阅读-------------