Docker CentOS图像不会自动启动httpd [英] Docker CentOS image does not auto start httpd

查看:263
本文介绍了Docker CentOS图像不会自动启动httpd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Apache和PHP程序来运行一个简单的Docker映像。如果我运行

  docker运行-t -i -p 80:80我/ httpd / bin / bash 

然后手动启动Apache

 code> service httpd start 

但是,我无法让httpd在运行时自动启动

  docker run -d -p 80:80 my / httpd 

Apache将启动然后容器存在。我已经在我的码头文件中尝试了一堆不同的 CMD

  CMD /etc/init.d/httpd start 
CMD [servicehttpdstart]
CMD [/ bin / bash,/etc/init.d/httpd start ]
ENTRYPOINT /etc/init.d/httpd CMD start
CMD ./start.sh

start.sh是

 #!/ bin / bash 
/etc/init.d/ httpd start

但是,apache启动后,每个停泊点的实例都将存在



我缺少一些非常明显的东西?

解决方案

你需要直接运行apache(httpd)不应该使用init.d脚本。



两个选项:


  1. 你必须在前台运行apache: / usr / sbin / apache2 -DFOREGROUND ... (或CentOS中的/ usr / sbin / httpd)

  2. 您必须启动所有服务(包括配置为自动运行的apache)通过执行 / sbin / init 作为入口点。

看到这个漂亮的帖子: http://www.kstaken.com/blog/2013/07/06/how-to-run-apache-under-docker/


I'm trying to run a simple Docker image with Apache and a PHP program. It works fine if I run

docker run -t -i -p 80:80 my/httpd /bin/bash

then manually start Apache

service httpd start

however I cant get httpd to start automatically when running

docker run -d -p 80:80 my/httpd

Apache will startup then container exists. I have tried a bunch of different CMDs in my docker file

CMD /etc/init.d/httpd start
CMD ["service" "httpd" "start"]
CMD ["/bin/bash", "/etc/init.d/httpd start"]
ENTRYPOINT /etc/init.d/httpd CMD start
CMD ./start.sh

start.sh is

#!/bin/bash
/etc/init.d/httpd start

However every-time docker instance will exist after apache starts

Am I missing something really obvious?

解决方案

You need to run apache (httpd) directly - you should not use init.d script.

Two options:

  1. you have to run apache in foreground: /usr/sbin/apache2 -DFOREGROUND ... (or /usr/sbin/httpd in CentOS)
  2. you have to start all services (including apache configured as auto-run) by executing /sbin/init as entrypoint.

See this nice post: http://www.kstaken.com/blog/2013/07/06/how-to-run-apache-under-docker/

这篇关于Docker CentOS图像不会自动启动httpd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆