Failed to get D-Bus connection: Operation not permitted


通過centos7鏡像創建了一個docker容器,並在容器中安裝了一個apache服務,但是啟動時發生如下報錯

[root@1346963c2247 ~]# rpm -qa | grep httpd
httpd-tools-2.4.6-45.el7.centos.4.x86_64
httpd-2.4.6-45.el7.centos.4.x86_64
[root@1346963c2247 ~]# systemctl start httpd
Failed to get D-Bus connection: Operation not permitted

出現此報錯的原因網絡上解釋說這是centos7容器的一個BUG,就是會在systemctl 啟動服務時出現報錯,此BUG將在centos7.2中得到解決。

解決措施如下:

sudo docker run -it --privileged centos /usr/sbin/init    在啟動docker容器時使用這種方式啟動,使用中方式啟動的弊端是等待過程可能要很長

# federico @ linux in ~ [15:30:07] C:1
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b255e96e1160 centos "/usr/sbin/init" 22 minutes ago Up 16 minutes agitated_hypatia
48082e41ebc5 centos "/bin/bash" About an hour ago Up About an hour pensive_lamport
1346963c2247 centos "/bin/bash" About an hour ago Up About an hour drunk_panini
ecb92e4f8374 centos "/bin/bash" About an hour ago Up About an hour suspicious_thompson

# federico @ linux in ~ [15:30:12]
$ sudo docker stop b255e96e1160
b255e96e1160

# federico @ linux in ~ [15:32:14]
$ sudo docker start b255e96e1160
b255e96e1160

在實驗過程中,我們可能不想浪費太多的時間,所以在這里我們打開一個新的終端將這個容器重啟(關閉->打開)

# federico @ linux in ~ [15:33:10]
$ sudo docker exec -it b255e96e1160 /bin/bash

docker自1.3版本起,提供了一個更加方便的工具exec,可以直接在容器中運行命令,例如我們使用我們剛剛新建的容器直接運行一個/bin/bash終端

[root@b255e96e1160 ~]# yum -y install net-tools httpd vim 

執行此命令安裝我們所需的軟件包

[root@b255e96e1160 ~]# systemctl start httpd
[root@b255e96e1160 ~]# netstat -antp | grep 80
tcp6 0 0 :::80 :::* LISTEN 139/httpd
[root@b255e96e1160 ~]# ps aux | grep httpd
root 139 0.0 0.0 221944 7488 ? Ss 07:39 0:00 /usr/sbin/httpd -DFOREGROUND
apache 140 0.0 0.0 221944 5900 ? S 07:39 0:00 /usr/sbin/httpd -DFOREGROUND
apache 141 0.0 0.0 221944 5900 ? S 07:39 0:00 /usr/sbin/httpd -DFOREGROUND
apache 142 0.0 0.0 221944 5900 ? S 07:39 0:00 /usr/sbin/httpd -DFOREGROUND
apache 143 0.0 0.0 221944 5900 ? S 07:39 0:00 /usr/sbin/httpd -DFOREGROUND
apache 144 0.0 0.0 221944 5900 ? S 07:39 0:00 /usr/sbin/httpd -DFOREGROUND
root 148 0.0 0.0 9040 804 ? S+ 07:40 0:00 grep --color=auto httpd
[root@b255e96e1160 ~]#

現在,我們遇到的問題已經得到了解決,但是筆者到現在還不知道有沒有更好的辦法,能夠在不用新建容器的情況下解決此問題,如果有前輩了解,望不吝告知謝謝!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM