docker堆栈部署不会删除当前yaml撰写文件中未声明的服务

我目前在pipe道中使用Docker Swarm模式,我使用大规模的docker stack deploy -c compose-file.yml name-of-the-stack作为命令来更新与最新的docker图像的堆栈。 它完美的作品,除非我不从yaml文件中删除服务。 在这种情况下, stack deploy命令应该在更新另一个服务的图像时除去不再存在的服务,但行为是它使容器运行,而这不是预期的行为。 因此,我改变了一个docker stack rm name-of-the-service ,然后docker stack deploy -c compose-file.yml name-of-stack 。 但是这有另一个可怕的副作用,随机影响容器:命令docker stack rm name-of-the-stack往往使nginx容器proxypass的可靠性完全不可靠(似乎与这个问题有关https://github.com/docker工人/docker工人/问题/ 24244 )。 事实上,nginx容器(在另一个栈中,但在同一个覆盖networking中)负责处理容器之间的所有请求,并使用Docker Swarm模式的路由网格特性在它们之间build立代理通道部署堆栈的重新创build,无法代理请求,就像试图将stream量转发到不再存在的容器一样,这会使集成和行为testing失败。 有没有一种方法来部署一致,而不使用docker堆栈RM(目前看起来很麻烦),但应用最新的YML组合文件的状态?

您需要在--prune docker stack deploy命令中包含--prune选项:

 $ docker stack deploy --help Usage: docker stack deploy [OPTIONS] STACK Deploy a new stack or update an existing stack Aliases: deploy, up Options: --bundle-file string Path to a Distributed Application Bundle file -c, --compose-file string Path to a Compose file --help Print usage --prune Prune services that are no longer referenced --with-registry-auth Send registry authentication details to Swarm agents 
Interesting Posts