无法在 docker 镜像中启动 httpd 服务

Gla*_*ost 1 httpd docker

我有以下 Dockerfile 应该启动 Centos 机器并安装 httpd:

FROM centos:centos6.6
RUN yum install -y httpd
RUN chkconfig httpd on; 
RUN /etc/init.d/httpd start
EXPOSE 80

CMD ["/bin/bash"]
Run Code Online (Sandbox Code Playgroud)

我构建图像:

docker build --no-cache -t centos_http .
Run Code Online (Sandbox Code Playgroud)

构建说:

...
Step 4/6 : RUN /etc/init.d/httpd start
---> Running in 0766e84ec292
Starting httpd: httpd: Could not reliably determine the server's fully  qualified domain name, using 172.17.0.2 for ServerName
[  OK  ]
...
Successfully built 5380a0bacdfb
Run Code Online (Sandbox Code Playgroud)

但是如果我运行图像:

docker run  -p 8090:80 -it  5380
[root@eda7400a46a9 /]# ps -ef | grep httpd | grep -v grep
[root@eda7400a46a9 /]# 
Run Code Online (Sandbox Code Playgroud)

httpd 没有运行!如果我手动执行 /etc/init.d/httpd start,在图像内部,它工作正常......

ALe*_*hha 5

你做的完全错了。RUN命令只会在构建期间执行。你应该使用类似下面的东西

FROM centos:6.6

RUN yum install -y httpd

EXPOSE 80

ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]
Run Code Online (Sandbox Code Playgroud)

你也可以看看官方的apache Dockerfile