简体   繁体   English

在docker swarm容器中使用pid 1重新启动进程(副本)

[英]Restarting process with pid 1 in docker swarm container (replica)

I have docker nginx running in docker swarm. 我有在docker swarm中运行的docker nginx。 I want to change settings of nginx without container restart. 我想在不重启容器的情况下更改Nginx的设置。 I replaced nginx conf file inside container but I cannot reload configuration 我替换了容器内的nginx conf文件,但无法重新加载配置

Tried 试过了

root@xxx:/# service nginx
Usage: /etc/init.d/nginx {start|stop|status|restart|reload|force-reload|upgrade|configtest}
root@xxx:/# service nginx reload
[....] Reloading nginx: nginxstart-stop-daemon: warning: failed to kill 1: Permission denied
 failed!
root@xxx:/# service nginx force-reload
[....] Reloading nginx: nginxstart-stop-daemon: warning: failed to kill 1: Permission denied
 failed!
root@xxx:/# nginx -s reload
2017/03/17 12:57:05 [notice] 281#281: signal process started
2017/03/17 12:57:05 [alert] 281#281: kill(1, 1) failed (13: Permission denied)
nginx: [alert] kill(1, 1) failed (13: Permission denied)


root@xxx:/# ps aux | grep nginx
root         1  0.0  0.1  36124  5500 ?        Ss   Mar09   0:00 nginx: master process nginx -g daemon off;
nginx        9  0.0  0.1  37328  4476 ?        S    Mar09   7:32 nginx: worker process
root       243  0.0  0.0  11128  1020 ?        S+   12:45   0:00 grep nginx    
root@xxx:/# kill -HUP 1
bash: kill: (1) - Permission denied

It is possible to do? 有可能吗?

You seem to be on the wrong track: The point of running services inside a docker swarm is that any instance can go away at any time (eg at node failure) and be replaced by a freshly created new one. 您似乎走错了轨道:在docker群中运行服务的要点是,任何实例都可以随时消失(例如,在节点发生故障时),并被新创建的新实例取代。 This means that you should not manipulate containers that belong to a service managed by a swarm cluster because your changes can get lost at any time. 这意味着您不应操纵属于群集集群管理的服务的容器,因为您的更改可能随时丢失。 You seem to have docker exec 'd into such a container and manually edited the config file. 您似乎已经将docker exec放入这样的容器中并手动编辑了配置文件。 This is a no-go. 这是不行的。 Your change is very volatile. 您的更改非常不稳定。

A better solution would be to create an image with your custom configuration for use in swarm. 更好的解决方案是使用您的自定义配置创建图像以用于群体。 Any time your config changes, update the image and replace the running instance(s) with docker service update --image my-custom-image:new-version <my-service> . 每当您的配置更改时,更新映像并用docker service update --image my-custom-image:new-version <my-service>替换正在运行的实例。 Docker will take care of rolling out the update. Docker将负责推出更新。 If your service is running with multiple instances, the update will cause no downtime (rolling update). 如果您的服务与多个实例一起运行,则该更新不会导致停机(滚动更新)。

That said, what you really asked for should work if you send the kill signal to the container from outside , eg docker kill -s HUP container-name issued on the Docker node where the service instance is actually running. 就是说,如果您从外部向容器发送kill信号,那么您真正要求的内容应该起作用,例如,在实际运行服务实例的Docker节点上发布的docker docker kill -s HUP container-name As you already modified the config inside the container, you obviously know how to find the container. 由于您已经修改了容器内部的配置,因此您显然知道如何找到容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM