Running apache in docker

Well, I have exhausted almost all the threads and articles, but still I can not get my apache web server to work offline on the Docer Centos container.

Here is my simplified dockerfile

# install apache RUN yum -y install httpd # start the webserver ADD startservice /startservice RUN chmod 775 /startservice EXPOSE 80 CMD ["/startservice"] 

My script service service just has

 #!/usr/bin/sh service httpd start 

I can build perfectly, but the container may not work in daemon / offline mode. How to do it?

I use this to run the container offline

 docker run -p 80:80 -d -t webserver 

I need to log into the container and start the service to start the web server.

 docker run -p 80:80 -i -t webserver bash service httpd start 
+2
source share
1 answer

This is a classic docker issue. The start of the process should be carried out in the foreground, otherwise the container simply stops.

So, in order to be able to do this, you can use the startervice script in your service:

 #!/usr/bin/sh service httpd start # Tail the log file tail -f /var/log/httpd/access_log # Alternatively, you can tail any file or even /dev/null #tail -f /dev/null 

Please note that there are other ways to resolve them. One way is to use a supervisord that supports your processes. The supervisor approach is cleaner and lollipop than the tail -f approach, and I personally would prefer this alternative.

Another alternative is simply that you do not start httpd as a service, but instead provide the -DFOREGROUND . This will force httpd to be attached to the shell (and not fork for the background process).

 /usr/sbin/httpd -DFOREGROUND 

For more information about http in foreground mode, select question .

+5
source

All Articles