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

标签 docker apache2 dockerfile

我已经创建了这个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/

    相关文章:

    docker - 相同的 Dockerfile 在构建过程中给出不同的结果

    docker - 在Docker容器中启动 `pktgen`应用程序时vdev_probe()失败

    proxy - Apache 和 Tomcat : ProxyPass and ProxyPassReverse

    Dockerfile - ENTRYPOINT 的 exec 形式和 CMD 的 shell 形式

    docker - Docker 1.9 中配置文件的位置是什么?

    ubuntu -/dev/mapper/docker-202 上的未知文件系统类型

    docker-compose up 不构建

    windows - Windows上的boot2docker - 无法访问暴露的端口

    ubuntu - Ubuntu 11.10 下的 Zend 框架 : internal server error with virtual server

    svn - 尝试设置 Apache+svn,但遇到了麻烦。 http ://localhost doesn't work