Search code examples
docker-swarm

Swarm service on every node but the manager


I have a swarm running with one manager and multiple workers.

I want a specific service to be deployed once (and only once) per node, but only on the workers. The manager still run other services.

What I found doesn't fit my needs:

  • mode: global do what I want for the 'once per container' but that does not exclude the manager.
  • mode: replicated replicas: 6 placement: constraints: - node.role == worker limit to the worker but with that solution there could be more than one replicas on a node. And --max-replicas-per-node doesn't exist yet.

  • docker node update --availability drain manager1 removes the manager from the workers, but that's not possible either because my manager should run other services.


Solution

  • You can combine your first solution with the second one. Something like this works well for me in my environment:

    mode: global placement: constraints: - node.role == worker

    The only issue would be that you need to assign a label (worker) to every node you need to run the service on.