在centos7的docker容器裏面不能用service啓動服務。
systemctl start httpd
報錯內容:Failed to get D-Bus connection: Operation not permitted。
網上查詢資料,說在docker run容器的時候加上 --privileged 參數,然而並無卵用。
報這個錯的原因是dbus-daemon沒能啓動。systemctl並不是不能使用。將CMD或者entrypoint設置爲/usr/sbin/init即可。docker容器會自動將dbus等服務啓動起來。如下:
docker run --privileged -ti --name test docker.io/centos:7 /usr/sbin/init