dwitz dwitz - 7 days ago 6x
Apache Configuration Question

Docker CentOS image does not auto start httpd

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
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 is

/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/