4

我目前在管道中使用 Docker Swarm 模式,并且我大量docker stack deploy -c compose-file.yml name-of-the-stack使用命令来使用最新的 docker 映像更新堆栈。除非我不从 yaml 文件中删除服务,否则它可以完美运行。在这种情况下,该stack deploy命令应该在更新另一个镜像的基础上删除不再存在的服务,但行为是它使容器保持运行,这不是预期的行为。因此,我用 a docker stack rm name-of-the-serviceand then改变了它docker stack deploy -c compose-file.yml name-of-stack。但这有另一个随机影响容器的可怕副作用:命令docker stack rm name-of-the-stack通常使 nginx 容器 proxypass 的可靠性完全不可靠(似乎与此问题有关https://github.com/docker/docker/issues/24244) . 事实上,nginx 容器(在另一个栈中但在同一个覆盖网络中),它负责处理容器之间的所有请求,并使用 Docker Swarm 模式的路由网格特性在它们之间进行代理传递,之后部署的堆栈的重新创建无法代理请求,例如,如果它试图将流量转发到不再存在的容器,这会使集成和行为测试失败。有没有一种方法可以在不使用 docker stack rm 的情况下进行一致的部署(到目前为止这似乎很麻烦),而是应用 yml compose 文件的最新状态?

4

1 回答 1

12

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

$ 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
于 2017-06-05T13:35:04.177 回答