Docker CentOS 映像不会自动启动 httpd [英] Docker CentOS image does not auto start httpd
问题描述
我正在尝试使用 Apache 和 PHP 程序运行一个简单的 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
然后手动启动Apache
then manually start Apache
service httpd start
但是我不能让 httpd 在运行时自动启动
however I cant get httpd to start automatically when running
docker run -d -p 80:80 my/httpd
Apache 将启动,然后容器存在.我在我的 docker 文件中尝试了一堆不同的 CMD
s
Apache will startup then container exists. I have tried a bunch of different CMD
s 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 是
#!/bin/bash
/etc/init.d/httpd start
但是每次 docker 实例在 apache 启动后都会存在
However every-time docker instance will exist after apache starts
我是否遗漏了一些非常明显的东西?
Am I missing something really obvious?
推荐答案
你需要直接运行 apache (httpd) - 你不应该使用 init.d 脚本.
You need to run apache (httpd) directly - you should not use init.d script.
两种选择:
- 您必须在前台运行 apache:
/usr/sbin/apache2 -DFOREGROUND ...
(或 CentOS 中的/usr/sbin/httpd) - 您必须通过执行
/sbin/init
作为入口点来启动所有服务(包括配置为自动运行的 apache).
- you have to run apache in foreground:
/usr/sbin/apache2 -DFOREGROUND ...
(or /usr/sbin/httpd in CentOS) - you have to start all services (including apache configured as auto-run) by executing
/sbin/init
as entrypoint.
这篇关于Docker CentOS 映像不会自动启动 httpd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!