Docker
無法在 docker 鏡像中啟動 httpd 服務
我有以下應該啟動 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
命令將僅在建構期間執行。你應該使用類似下面的東西FROM centos:6.6 RUN yum install -y httpd EXPOSE 80 ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]
你也可以看看官方的 apache Dockerfile