0

I have a docker swarm with 1 master node and 7 worker nodes across 3 machines all running tomcat containers.

I wish to deploy all my containers to only strictly 2 worker nodes.

How will i setup the affinity rule for such a deployment?

Can you please help me with the detailed steps on how to achieve this?

Neo Anderson
  • 5,957
  • 2
  • 12
  • 29
mohtashim
  • 57
  • 1
  • 8

1 Answers1

1

You can tag the 2 worker nodes:

docker node update --label-add foo=bar node-1
docker node update --label-add foo=bar node-2

and then use deploy placement constraints to force the container land on the nodes that you labeled in the previous step:

services:
  your-service:
    image: your-image
    deploy:
      placement:
        constraints: [node.labels.foo=bar ]
Neo Anderson
  • 5,957
  • 2
  • 12
  • 29