1. 程式人生 > >docker Failed to get D-Bus connection 報錯

docker Failed to get D-Bus connection 報錯

entry href poi moved red ger rep bug IT

docker Failed to get D-Bus connection 報錯

原創憬薇2016-01-15 11:25:26評論(10)40278人閱讀

在centos7的容器裏面出現了一個BUG,就是serveice啟動服務的時候出現報錯,不能用service啟動服務。
[root@e13c3d3802d0 /]# service httpd start
Redirecting to /bin/systemctl start httpd.service
Failed to get D-Bus connection: Operation not permitted

首先恭喜你使用centos7鏡像,然後就是不幸告訴你這個問題是個BUG 將在centos7.2解決。

Currently, systemd in CentOS 7 has been removed and replaced with a fakesystemd package for dependency resolution. This is due to systemd requiring the CAP_SYS_ADMIN capability, as well as being able to read the host‘s cgroups. If you wish to replace the fakesystemd package and use systemd normally, please follow the steps below.

我查了好多地方都說是個BUG不能解決
有的說創建的時候加上 --privileged選項

我試了這些然而並沒有任何的卵用

最後實在是沒辦法就 rpm -ql 軟件包 查看安裝的時候有哪些命令在PATH下,用這些命令去啟動,這個是一種解決的方法
例如apache的啟動就是用命令 httpd


這幾天研究了個解決的辦法比較靠譜,親身實測好使:
systemctl start http.service
Failed to get D-Bus connection: No connection to service manager.

這個的原因是因為dbus-daemon沒能啟動。其實systemctl並不是不可以使用。將你的CMD或者entrypoint設置為/usr/sbin/init即可。會自動將dbus等服務啟動起來。
然後就可以使用systemctl了。命令如下:
docker run --privileged -ti -e "container=docker" -v /sys/fs/cgroup:/sys/fs/cgroup centos /usr/sbin/init

docker Failed to get D-Bus connection 報錯