Centos7 adminset Docker容器中报错 Failed to get D-Bus connection: Operation not permitted

2019年11月21日

报错的原因:

在运行的docker容器中 执行命令启动nginx

    [root@Localhost ~]# docker run -p 0.0.0.0:1030:22 0.0.0.0:8800:80 -t -i --name AdminSet centos     
    [root@03e74fb601c1 /]# systemctl start nginx    
    Failed to get D-Bus connection: Operation not permitted

 如果要是用systemctl 管理服务就要加上参数 --privileged 来增加权,并且不能使用默认的bash,换成 init,命令如下

    [root@Localhost ~]# docker run -p 0.0.0.0:1030:22 -p 0.0.0.0:8800:80 -d -t -i --privileged --name AdminSet centos:7.2 /usr/sbin/init
    0a660dc03f333919fcf22854da065d46c5231e8c140e636656c1bbbe497f9b62
    [root@Localhost ~]# docker ps
   CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS                      PORTS                                                                  NAMES
   4d17fe1d1c7f        centos:7.2                        "/usr/sbin/init"         15 minutes ago      Up 15 minutes               0.0.0.0:1030->22/tcp, 0.0.0.0:8800->80/tcp                             AdminSet

 

以后台模式运行我再进入到容器里操作

     

    [root@Localhost ~]# docker exec -it 4d17fe1d1c7f  /bin/bash
    [root@0a660dc03f33 /]# systemctl start nginx
    [root@0a660dc03f33 /]# 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/0a660dc03f333919fcf22854da065d46c5231e8c140e636656c1bbbe497f9b62/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/nginx

    Feb 27 11:43:04 0a660dc03f33 systemd[1]: Starting The nginx HTTP and reverse proxy server...
    Feb 27 11:43:04 0a660dc03f33 nginx[4220]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    Feb 27 11:43:04 0a660dc03f33 nginx[4220]: nginx: configuration file /etc/nginx/nginx.conf test is successful
    Feb 27 11:43:04 0a660dc03f33 systemd[1]: Started The nginx HTTP and reverse proxy server.

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注