Docker swarm - 如何在 swarm 中的每个节点上复制服务

Docker swarm - how to replicate a service on each node in the swarm

我想将堆栈部署到 docker 群,我希望每个节点都运行 给定服务。

我查看了 deploy.placement 配置,发现最接近的选项是放置首选项 spread=node.label.abc,它将在与标签匹配的节点上平均分配服务。但是,这需要始终更新副本计数以匹配节点数。

有没有办法在所有节点上自动部署服务而无需手动更新副本数?

Is there a way to automatically deploy a service on all the nodes without manually updating the replica count?

是的,在 global mode 中部署您的服务而不是复制。来自 link 的示例:

version: '3'
services:
  worker:
    image: dockersamples/examplevotingapp_worker
    deploy:
      mode: global

这将 运行 每个符合您的约束的节点上的容器实例。