在centos7的docker容器裏面不能用service啓動服務。
systemctl start sshd
報錯內容:Failed to get D-Bus connection: Operation not permitted。
報這個錯的原因是dbus-daemon沒能啓動。systemctl並不是不能使用。將CMD或者entrypoint設置爲/usr/sbin/init即可。docker容器會自動將dbus等服務啓動起來。如下:
docker run --privileged -ti --name test1 centos /usr/sbin/init
需要注意的是,docker 容器運行Ubuntu遇到類似的問題時:
System has not been booted with systemd as init system (PID 1). Can't operate.
/usr/sbin與/sbin並不是鏈接關係,在/usr/sbin下沒有init的
docker run --privileged -ti --name test1 ubuntu /sbin/init
轉載自:https://blog.csdn.net/shenzhen_zsw/article/details/73928195