I have created this docker image:
FROM debian:jessie
RUN apt-get update && apt-get install -y apache2 python-pip libapache2-mod-wsgi l
RUN pip install django
CMD ["/usr/sbin/apache2ctl","-DFOREGROUND"]
When I run a container, I am invoking --restart=always argument.
So if I reboot computer host, the container will automatically restart.
But, there is a problem: apache2 pid file is not removed, so apache2 cannot restart. I have to manually remove pid file and everything is ok.
I have 2 questions:
Why this pid file does not create any problem on a physical computer ? Is it possible to tell apache to erase this pid file at startup ?
Is it possible to put a "pre-CMD" command in docker file ? A sort of CMD which would be run before apache2ctl ?
Is it possible to put a "pre-CMD" command in docker file ?
As mentioned in docker-library/php issue 53:
I did it with cleanup old PID is exist in my startup entry.
See as an example PR 59 and its new apache2-foreground starting script:
#!/bin/bash
set -e
# Apache gets grumpy about PID files pre-existing
rm -f /var/run/apache2/apache2.pid
exec apache2 -DFOREGROUND
The Dockerfile install that script:
COPY apache2-foreground /usr/local/bin/
Why this pid file does not create any problem on a physical computer ?
The aforementioned issue included this comment:
I've run into this a few times myself, particularly when I've let the containers be stopped by running sudo stop docker (either directly or during a reboot). I just looked through how the init scripts and shutdown work under Ubuntu/Debian and it looks like everything just tries to shut down too fast and that all the containers are shut down in series.
If you've got one container that stops slowly (ahem, memcached...), then you can easily run into the situation where your containers are not stopped cleanly. I've generally been fortunate enough in most cases to be able to just delete the container and recreate it from scratch, but that can be a hard pill to swallow if all you've done is try to do a graceful reboot.
Then:
Is it possible to tell apache to erase this pid file at startup ?
md5 added:
I also looked at the httpd source code and found that there's no good way to make Apache deal with this situation itself (cf. https://github.com/apache/httpd/blob/2.4.x/server/mpm_unix.c#L768) Is it possible to tell apache to erase this pid file at startup ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With