gpt4 book ai didi

docker - 为什么apache2在docker image重启时不删除pid文件

转载 作者:行者123 更新时间:2023-12-02 18:23:46 24 4
gpt4 key购买 nike

我已经创建了这个Docker镜像:

 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"]

运行容器时,我正在调用 --restart=always参数。
因此,如果我重新启动计算机主机,则容器将自动重新启动。
但是,有一个问题:apache2 pid文件未删除,因此apache2无法重新启动。我必须手动删除pid文件,一切正常。

我有两个问题:
  • 为什么此pid文件在物理计算机上不会产生任何问题?是否可以告诉apache在启动时删除此pid文件?
  • 是否可以在docker文件中放置“pre-CMD”命令?一种CMD,它将在apache2ctl之前运行?
  • 最佳答案

    Is it possible to put a "pre-CMD" command in docker file ?


    docker-library/php issue 53中所述:

    I did it with cleanup old PID is exist in my startup entry.


    PR 59及其新的 apache2-foreground 起始脚本为例:
    #!/bin/bash
    set -e

    # Apache gets grumpy about PID files pre-existing
    rm -f /var/run/apache2/apache2.pid

    exec apache2 -DFOREGROUND
    Dockerfile安装该脚本:
    COPY apache2-foreground /usr/local/bin/

    为什么此pid文件在物理计算机上不会产生任何问题?
    上述问题包括以下评论:

    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.


    然后:

    Is it possible to tell apache to erase this pid file at startup ?


    md5添加了:

    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 ?

    关于docker - 为什么apache2在docker image重启时不删除pid文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39803465/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com