docker容器内无法使用systemctl

问题:
在docker容器中使用systemctl命令报错

powershell
[root@707a5892dae2 /]# systemctl start nginx
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down


解决办法:
运行容器时添加`--privileged=true`,修改/bin/bash为/sbin/init
[root@919 ~]# docker run -itd --name nginxv2 --privileged=true centos /usr/sbin/init 

验证:
powershell
[root@919 ~]# docker exec -it nginxv2 /bin/bash
[root@491ab139e4fd /]# systemctl start nginx
[root@491ab139e4fd /]# ps -ef |grep nginx
root         187       1  0 02:32 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx        188     187  0 02:32 ?        00:00:00 nginx: worker process
上一篇:代码的印象派:写点好代码吧


下一篇:NPM修改镜像地址