0

How made ban more than one container on a node with use: Docker, Swarm, Compose? For example I have 5 nodes and I want deploy 3 replicas some service and I want that this replicas will be on different nodes.

Lorna Mitchell
  • 1,819
  • 13
  • 22
Ivan Bukharin
  • 321
  • 2
  • 4
  • 22

1 Answers1

0

Docker's swarm mode currently defaults to an HA scheduling strategy, so there's nothing needed to get your service spread across multiple nodes as long as there are multiple available nodes to schedule the task on. Constraints, memory restrictions, and outages may impact the available nodes that is has to schedule a task on. The HA scheduler first searches for candidate nodes that have the fewest instances of a task (typically 0 unless you have more replicas than nodes), and then it tie breaks the resulting list by favoring nodes with fewer tasks.

For further control to spread out a task on multiple nodes, I'd recommend looking into the placement preferences added in recent versions. I don't believe this has made it into stacks and the compose file yet, but I expect that's only a matter of time until it does (new swarm mode features are first introduced to the docker service command line and later added to higher level abstractions). The placement preferences allow you to label your nodes to indicate a higher level topology, e.g. common racks, switches, or datacenters. And the placement preferences enable topology aware scheduling that can spread the tasks out among nodes with unique values of the desired label. So if you have two separate racks with 5 nodes each, without the topology aware scheduling everything could be scheduled on a single rack, and with the topology aware scheduling, it could put half of your tasks on each rack.

BMitch
  • 231,797
  • 42
  • 475
  • 450