Centos7 Docker容器中报错 Failed to get D-Bus connection: Operation not permitted
报错的原因:在运行的docker容器中 执行命令启动nginx[root@node132 ~]# docker run -it nginx-1 /bin/bash[root@03e74fb601c1 /]# systemctl start nginxFailed to get D-Bus connection: Operation not permitted如...
报错的原因:
在运行的docker容器中 执行命令启动nginx
[root@node132 ~]# docker run -it nginx-1 /bin/bash
[root@03e74fb601c1 /]# systemctl start nginx
Failed to get D-Bus connection: Operation not permitted
如果要是用systemctl 管理服务就要加上参数 --privileged 来增加权,并且不能使用默认的bash,换成 init,命令如下
[root@node132 ~]# docker run -d -it --privileged nginx-1 /usr/sbin/init
362306ddc6f03919fcf22854da065d46c5231e8c140e636656c1bbbe497f9b62
[root@node132 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
362306ddc6f0 nginx-1 "/usr/sbin/init" 2 seconds ago Up 1 second
以后台模式运行我再进入到容器里操作
[root@node132 ~]# docker exec -it 3623 /bin/bash
[root@362306ddc6f0 /]# systemctl start nginx
[root@362306ddc6f0 /]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2019-02-27 11:43:04 UTC; 6s ago
Process: 4221 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 4220 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 4219 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 4222 (nginx)
CGroup: /docker/362306ddc6f03919fcf22854da065d46c5231e8c140e636656c1bbbe497f9b62/system.slice/nginx.service
├─4222 nginx: master process /usr/sbin/nginx
├─4223 nginx: worker process
├─4224 nginx: worker process
├─4225 nginx: worker process
└─4226 nginx: worker process
‣ 4222 nginx: master process /usr/sbin/nginxFeb 27 11:43:04 362306ddc6f0 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Feb 27 11:43:04 362306ddc6f0 nginx[4220]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 27 11:43:04 362306ddc6f0 nginx[4220]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 27 11:43:04 362306ddc6f0 systemd[1]: Started The nginx HTTP and reverse proxy server.
至此问题解决
更多推荐
所有评论(0)