【发布时间】: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;"]。