我有以下 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