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

我有Docker群中运行的docker nginx。 我想改变nginx的设置,而无需重启容器。 我更换了容器内的nginx conf文件,但无法重新加载configuration

试着

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 

有可能吗?

你似乎走错了路线:在Docker群体中运行服务的关键是,任何实例可以随时消失(例如在节点故障时),并由新创build的新实例替代。 这意味着您不应该操作属于由群集pipe理的服务的容器,因为您的更改可能会随时丢失。 你似乎有docker exec到这样的容器,并手动编辑configuration文件。 这是不行的。 你的变化非常不稳定。

更好的解决scheme是创build一个自定义configuration的图像用于swarm。 任何时候你的configuration发生变化,更新镜像,并用docker service update --image my-custom-image:new-version <my-service>replace正在运行的实例。 Docker将负责推出更新。 如果您的服务正在运行多个实例,则更新不会导致停机(滚动更新)。

也就是说,如果从外部发送kill信号到容器,例如docker kill -s HUP container-name ,在服务实例正在运行的Docker节点上发出,那么你真正要求的东西应该起作用。 由于您已经修改了容器内的configuration,您显然知道如何find容器。