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 likeworker
orevent
, while sites requiring stability or compatibility with older software can use aprefork
.
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/mod_mpm_prefork.so,LoadModule mpm_prefork_module modules/mod_mpm_prefork.so,g' /usr/local/apache2/conf/httpd.conf
RUN sed -i 's,LoadModule mpm_event_module modules/mod_mpm_event.so,#LoadModule mpm_event_module modules/mod_mpm_event.so,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!
thank you so much it works
Thanks for this