httpd Docker container issue: a possible workaround 2

Last week I was deploying some Docker containers on a staging virtual machine and I faced an issue with a httpd:2.4 Docker image. The container started and then immediately exited with code 0. All containers worked fine, but the only one running httpd for some reason failed. The docker logs command showed something like this:

httpd AH02324: A resource shortage or other unrecoverable failure was encountered before any child process initialized successfully... httpd is exiting!

At first sight, I thought about a lack of resources, since the virtual machine hosted about 27 containers and was about to swap. So, I increased the CPUs from 2 to 4 and I doubled the RAM, from 8 GB to 16 GB, but this didn’t solve the problem.

So, I started to investigate about the Apache Multi-Processing Modules (MPMs), and at some point I noticed the following statement:

The server can be better customized for the needs of the particular site. For example, sites that need a great deal of scalability can choose to use a threaded MPM like worker or event, while sites requiring stability or compatibility with older software can use a prefork.

Since the virtual machine was running CentOS 7 with a very old version of Docker (v1.13.1), I realized that I could try to replace the mpm_event module with mpm_prefork by just adding the following lines into the Dockerfile:

RUN sed -i 's,#LoadModule mpm_prefork_module modules/,LoadModule mpm_prefork_module modules/,g' /usr/local/apache2/conf/httpd.conf
RUN sed -i 's,LoadModule mpm_event_module modules/,#LoadModule mpm_event_module modules/,g' /usr/local/apache2/conf/httpd.conf

In my specific case these two lines solved the issue and then I was able to run the container!

Did you like this post? Share it!
Share on email
Share on twitter
Share on facebook
Share on linkedin
Share on print

2 thoughts on “httpd Docker container issue: a possible workaround

  1. Reply Amit Oct 30,2023 06:00

    thank you so much it works

  2. Reply PLOPS Nov 3,2023 20:51

    Thanks for this

Leave a Reply