php 如何在不终止docker容器的情况下重新启动apache2?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37523338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:16:11  来源:igfitidea点击:

How to restart apache2 without terminating docker container?

phpapachedockerdocker-compose

提问by k0pernikus

I am using as a base the php docker containerwith the tag:

我使用带有标签的php docker 容器作为基础:

php:5.6-apache

When I try to restart the apache2 inside the container, the container stops:

当我尝试重新启动容器内的 apache2 时,容器停止:

root@phalconapp:/var/www/html# service apache2 restart
Restarting web server: apache2Terminated
root@phaclonapp:/var/www/html#
me@myLocalComputer:

How to restart apache2 without stopping the container?

如何在不停止容器的情况下重新启动 apache2?

I want to play around with the container and customize it, before I put my changes into the dockerfile. I want to install some extension and for them to work I need to restart apache for the changes to take effect.

在将更改放入 dockerfile 之前,我想使用容器并对其进行自定义。我想安装一些扩展并让它们工作,我需要重新启动 apache 以使更改生效。

This is the log file via:

这是日志文件通过:

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

回答by Cauê Alves Braz

If you use apache as the primary service to keep your running container, you can NOT reboot it. Simply because you built the image and sets the CMD with it.

如果您使用 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.

CMD 的主要目的是为正在执行的容器提供默认值。这些默认值可以包含可执行文件,也可以省略可执行文件,在这种情况下,您还必须指定 ENTRYPOINT 指令。

Try to reload without restart a service:

尝试在不重启服务的情况下重新加载:

/etc/init.d/apache2 reload

回答by Tim Malone

My solution to this was to exit my bash shell into the container, and just restart the container outside of Docker. Because Apache is set as the primary service, this also restarts Apache, and doesn't crash the container.

我对此的解决方案是将我的 bash shell 退出到容器中,然后在 Docker 之外重新启动容器。因为 Apache 被设置为主要服务,这也会重新启动 Apache,并且不会使容器崩溃。

docker restart <container>

回答by Destrif

sudo docker kill --signal="USR1" your_appache_container

sudo docker kill --signal="USR1" your_appache_container

Other signals that you can use to achieve the following :

可用于实现以下目的的其他信号:

Stop Now Signal: TERM

立即停止信号:TERM

Graceful Restart Signal: USR1

正常重启信号:USR1

Restart Now Signal: HUP

立即重启信号:HUP

Graceful Stop Signal: WINCH

优雅停止信号:WINCH

From:this website

来自:本网站

回答by so-random-dude

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.

我想自定义容器,我需要安装一些扩展,为了让它们工作,我需要重新启动 apache 以使更改生效。

This is against the Docker's immutable infrastructure principle. IMHO, you are using the docker container similar to a full blown VM. Instead, I would suggest you to treat the docker image as the final artifact and version it. Note:This is just my humble opinion, you may have a valid usecase which I am not aware of, which I am curious to find out.

这违背了 Docker 的不可变基础设施原则。恕我直言,您正在使用类似于完整 VM 的 docker 容器。相反,我建议您将 docker 映像视为最终工件并对其进行版本控制。 注意:这只是我的拙见,您可能有一个我不知道的有效用例,我很想知道。

回答by Vineeth

But before going, does your apache fails while doing the restart? Thats how it exits? In that case, please do make it run by setting right configurations and having a look at those logs.

但是在去之前,你的apache在重启时失败了吗?就是这样退出的?在这种情况下,请通过设置正确的配置并查看这些日志来使其运行。

One method you can try is login to the container (to bash) and you could always have a docker commitat a point where it works. You can then change your base container image to that.

您可以尝试的一种方法是登录到容器(进行 bash),并且您始终可以在其工作时进行docker 提交。然后,您可以将基本容器映像更改为该映像。

I had workarounds for similar situations by building new images from these committedones using different ENTRYPOINT's in my Dockefile.

通过在我的 Dockefile 中使用不同的ENTRYPOINT从这些提交的图像构建新图像,我对类似情况有了解决方法。