如何在不终止 docker 容器的情况下重启 apache2?
How to restart apache2 without terminating docker container?
我使用带有标签的 php docker container 作为基础:
php:5.6-apache
当我尝试重启容器内的 apache2 时,容器停止:
root@phalconapp:/var/www/html# service apache2 restart
Restarting web server: apache2Terminated
root@phaclonapp:/var/www/html#
me@myLocalComputer:
如何在不停止容器的情况下重启apache2?
在将更改放入 dockerfile 之前,我想尝试使用容器并自定义它。我想安装一些扩展,为了让它们工作,我需要重新启动 apache 以使更改生效。
这是日志文件来自:
Attaching to dltasklight_phlaconapp_1
phlaconapp_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
phlaconapp_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
phlaconapp_1 | [Mon May 30 10:19:24.556154 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.22 configured -- resuming normal operations
phlaconapp_1 | [Mon May 30 10:19:24.556181 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
phlaconapp_1 | [Mon May 30 10:21:11.754993 2016] [mpm_prefork:notice] [pid 1] AH00169: caught SIGTERM, shutting down
dltasklight_phlaconapp_1 exited with code 0
sudo docker kill --signal="USR1" your_appache_container
您可以用来实现以下目标的其他信号:
立即停止信号:TERM
优雅重启信号:USR1
立即重启信号:HUP
优雅停止信号:WINCH
发件人: this website
如果您使用 apache 作为主要服务来保留您的 运行 容器,则无法重新启动它。仅仅是因为您构建了映像并使用它设置了 CMD。
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
尝试在不重新启动服务的情况下重新加载:
/etc/init.d/apache2 reload
我的解决方案是将 bash shell 退出到容器中,然后在 Docker 之外重新启动容器。因为 Apache 被设置为主要服务,这也会重新启动 Apache,并且不会使容器崩溃。
docker restart <container>
但是在开始之前,您的 apache 是否在重启时失败了?就这样退出了?在这种情况下,请通过设置正确的配置并查看这些日志来实现 运行。
您可以尝试的一种方法是登录到容器(到 bash)并且您总是可以在它所在的位置进行 docker 提交作品。然后,您可以将基础容器映像更改为该映像。
我通过在我的 Dockefile 中使用不同的 ENTRYPOINT 从这些 committed 构建新图像来解决类似情况。
I want to customize the container, I need to install some extension
and for them to work I need to restart apache for the changes to take
effect.
这违反了 Docker 的不可变基础设施原则。恕我直言,您正在使用类似于成熟 VM 的 docker 容器。相反,我建议您将 docker 图像视为最终工件并对其进行版本控制。
注意:这只是我的拙见,您可能有一个我不知道的有效用例,我很想知道。
在 docker 中,我使用这样的命令:
exec /usr/sbin/httpd -D FOREGROUND
我使用带有标签的 php docker container 作为基础:
php:5.6-apache
当我尝试重启容器内的 apache2 时,容器停止:
root@phalconapp:/var/www/html# service apache2 restart
Restarting web server: apache2Terminated
root@phaclonapp:/var/www/html#
me@myLocalComputer:
如何在不停止容器的情况下重启apache2?
在将更改放入 dockerfile 之前,我想尝试使用容器并自定义它。我想安装一些扩展,为了让它们工作,我需要重新启动 apache 以使更改生效。
这是日志文件来自:
Attaching to dltasklight_phlaconapp_1
phlaconapp_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
phlaconapp_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
phlaconapp_1 | [Mon May 30 10:19:24.556154 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.22 configured -- resuming normal operations
phlaconapp_1 | [Mon May 30 10:19:24.556181 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
phlaconapp_1 | [Mon May 30 10:21:11.754993 2016] [mpm_prefork:notice] [pid 1] AH00169: caught SIGTERM, shutting down
dltasklight_phlaconapp_1 exited with code 0
sudo docker kill --signal="USR1" your_appache_container
您可以用来实现以下目标的其他信号:
立即停止信号:TERM
优雅重启信号:USR1
立即重启信号:HUP
优雅停止信号:WINCH
发件人: this website
如果您使用 apache 作为主要服务来保留您的 运行 容器,则无法重新启动它。仅仅是因为您构建了映像并使用它设置了 CMD。
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
尝试在不重新启动服务的情况下重新加载:
/etc/init.d/apache2 reload
我的解决方案是将 bash shell 退出到容器中,然后在 Docker 之外重新启动容器。因为 Apache 被设置为主要服务,这也会重新启动 Apache,并且不会使容器崩溃。
docker restart <container>
但是在开始之前,您的 apache 是否在重启时失败了?就这样退出了?在这种情况下,请通过设置正确的配置并查看这些日志来实现 运行。
您可以尝试的一种方法是登录到容器(到 bash)并且您总是可以在它所在的位置进行 docker 提交作品。然后,您可以将基础容器映像更改为该映像。
我通过在我的 Dockefile 中使用不同的 ENTRYPOINT 从这些 committed 构建新图像来解决类似情况。
I want to customize the container, I need to install some extension and for them to work I need to restart apache for the changes to take effect.
这违反了 Docker 的不可变基础设施原则。恕我直言,您正在使用类似于成熟 VM 的 docker 容器。相反,我建议您将 docker 图像视为最终工件并对其进行版本控制。 注意:这只是我的拙见,您可能有一个我不知道的有效用例,我很想知道。
在 docker 中,我使用这样的命令:
exec /usr/sbin/httpd -D FOREGROUND