1. 程式人生 > >配置centos7解決 docker Failed to get D-Bus connection 報錯

配置centos7解決 docker Failed to get D-Bus connection 報錯

在centos7的容器裡面出現了一個BUG,就是serveice啟動服務的時候出現報錯,不能用service啟動服務。
[[email protected] /]# 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
  

wKioL1aYZnmScBPBAACZceqF4D8620.png  

  輕鬆無壓力解決