我有以下应该启动 centos 机器并安装 httpd 的 Dockerfile:
FROM centos:centos6.6
RUN yum install -y httpd
RUN chkconfig httpd on;
RUN /etc/init.d/httpd start
EXPOSE 80
CMD ["/bin/bash"]
我构建图像:
docker build --no-cache -t centos_http .
构建说:
...
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
但是如果我运行图像:
docker run -p 8090:80 -it 5380
[root@eda7400a46a9 /]# ps -ef | grep httpd | grep -v grep
[root@eda7400a46a9 /]#
httpd 没有运行!如果我在图像内部手动执行 /etc/init.d/httpd start,它工作正常......
你做错了。
RUN
命令将仅在构建期间执行。你应该使用类似下面的东西你也可以看看官方的 apache Dockerfile