我想用alpine和apache创建一个docker图像.我使用tini作为“init”系统.它工作,直到我分离并重新连接到容器.连接到容器后,apache退出并且容器停止.我不知道问题是什么.有没有人与docker,alpine和apache有类似的问题?
我的Dockerfile看起来像这样(之前,我使用Alpines包管理器进行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"]
输入和输出到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
更新:
问题似乎是apache2,当docker连接到容器时接收SIGWINCH(窗口大小更改):
[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滥用信号与apachectl实用程序一起正常关闭服务器.是否有可能阻止此信号,以便它不会被归结为apache?
最佳答案
确实,Apache使用SIGWINCH来触发正常关闭:
docker kill ----signal=SIGWINCH apache
docker-library/httpd issue 9提到
Even just dropping “
-t
” should remove the sending ofSIGWINCH
when the window resizes.
实际上,你只需要-d:见 PR669.
在您的情况下,您已经使用-dit运行映像,因此请检查是否只保留-d可能会有所帮助.
原始问题(在httpd端,而不是docker)在bug id 1212224中描述.
if I don’t connect a tty the signal isn’t send
因此,如果可能,请避免使用-t,如果需要,可以在需要时添加docker exec -t
session.