【问题标题】:Failed to get D-Bus connection: Operation not permitted [docker] [duplicate]无法获得 D-Bus 连接:不允许操作 [docker] [重复]
【发布时间】:2020-08-20 14:35:06
【问题描述】:

我正在尝试创建一个 docker 映像 (centos7),并在其上运行 nginx Web 服务器。我创建了一个Dockerfile,如下所示:

FROM centos:centos7

RUN yum update -y

# -------- OPENSSL -------- 

#ADD install-openssl.sh /
#RUN chmod +x install-openssl.sh
#RUN /install-openssl.sh

# -------- NGINX --------

RUN yum install epel-release -y
RUN yum install nginx -y

# Copy a configuration file from the current directory 
ADD nginx.conf /etc/nginx/

# Append "daemon off:" to the beginning of the configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Expose ports
EXPOSE 80

RUN systemctl start nginx

我使用以下命令构建我的 docker 映像:

docker build -t nginx-img .

我是这样运行的:

docker -v run --name nginx-cont -p 80:80 -i  nginx-img

但我收到以下错误:

Failed to get D-Bus connection: Operation not permitted

【问题讨论】:

  • 你根本不能在 Docker 中使用systemctl(或service 或初始化脚本)。使您的图像的CMD 运行您尝试作为前台进程运行的程序:CMD ["nginx", "-g", "daemon off;"]

标签: docker nginx systemctl


【解决方案1】:

您需要 centos7 systemd image 在容器内运行 systemctl

一旦你有了图像,

改变

From centos:centos7 line in the dockerfile

From <new image name>

就是这样,你会很高兴的

服务器端可以直接使用nginx图片

【讨论】:

    猜你喜欢
    • 2018-10-27
    • 2020-03-13
    • 1970-01-01
    • 2019-10-10
    • 2014-10-27
    • 2017-11-03
    • 2020-09-07
    • 1970-01-01
    • 2018-12-09
    相关资源
    最近更新 更多