我有以下 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"]
我构建了图像:
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,它可以正常工作...
答案1
你的做法完全错误。RUN
命令只会在构建期间执行。你应该使用类似下面的命令
FROM centos:6.6
RUN yum install -y httpd
EXPOSE 80
ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]
你也可以看看官方 apache Dockerfile