I want to create a docker image with alpine and apache. I use tini as an "init"-System. It works until i detach and reattach to the container. After attaching to the container apache exits and the container stops. I dont't know what the problem is. Do anybody had similar problems with docker, alpine and apache?
My Dockerfile looks like this (Before, I used Alpines package manager for tini)
FROM alpine
ENV TINI_VERSION v0.16.1
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /sbin/tini
RUN chmod +x /sbin/tini
RUN apk add --no-cache apache2 \
&& mkdir -p /run/apache2 \
&& ln -sf /dev/stdout /var/log/apache2/access.log \
&& ln -sf /dev/stderr /var/log/apache2/error.log
EXPOSE 80
ENTRYPOINT ["/sbin/tini", "-vvv", "-g", "--"]
CMD ["/usr/sbin/httpd", "-f", "/etc/apache2/httpd.conf", "-DFOREGROUND"]
Input and Output to docker cli:
~/Desktop/docker_test@laptop-sebi
$ docker run -itd test1
a793bad5d4350f58893909f1552c9f2978d8e2952960ac667f8dcb2bf7a3516e
~/Desktop/docker_test@laptop-sebi
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
a793bad5d435 test1 "/sbin/tini -vvv -..." 12 seconds
ago Up 11 seconds 80/tcp sharp_neumann
~/Desktop/docker_test@laptop-sebi
$ docker attach a7
[DEBUG tini (1)] Received SIGCHLD
[DEBUG tini (1)] Reaped child with pid: '5'
[INFO tini (1)] Main child exited normally (with status '0')
[TRACE tini (1)] No child to wait
[TRACE tini (1)] Exiting: child has exited
Update: The problem seems to be apache2, which receives the SIGWINCH (Window Size Change) while docker attachs to the container:
[Sun Oct 15 12:13:24.592575 2017] [mpm_prefork:notice] [pid 5] AH00170: caught SIGWINCH, shutting down gracefully
[DEBUG tini (1)] Received SIGCHLD
[DEBUG tini (1)] Reaped child with pid: '5'
[INFO tini (1)] Main child exited normally (with status '0')
[TRACE tini (1)] No child to wait
[TRACE tini (1)] Exiting: child has exited
Apache misuses the signal in conjunction with the apachectl utility to gracefully shut down the server. Is it possible to block this signal so it wouldn't be hand down to apache?
It is true that Apache uses SIGWINCH to trigger a graceful shutdown:
docker kill ----signal=SIGWINCH apache
docker-library/httpd issue 9 mentions
Even just dropping "
-t
" should remove the sending ofSIGWINCH
when the window resizes.
Actually, you need just -d
: see PR669.
In your case, you already running the image with -dit
, so check if just keeping -d
might help.
The original issue (on httpd side, not docker) is described in bug id 1212224.
The OP Sebi2020 confirms in the comments:
if I don't connect a tty the signal isn't send
So if possible, avoid the -t
and, if needed, add a docker exec -t
session if you need tty.
You could try switching your CMD
instruction from exec form
to shell form
which leads to /bin/sh -c <...>
being used when the container is run:
CMD /usr/sbin/httpd -f /etc/apache2/httpd.conf -DFOREGROUND
# or use ENTRYPOINT with the same shell form
It then no longer has PID 1 and Unix signals are not passed down to subprocesses.
But I am not sure (depending on your workflow) if you can attach
or exec -it
to or stop
the container as you would like to.
References:
http://www.johnzaccone.io/entrypoint-vs-cmd-back-to-basics/
(Fact 3)
https://docs.docker.com/engine/reference/builder/#cmd
https://docs.docker.com/engine/reference/builder/#shell-form-entrypoint-example
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