Docker Community Forums

Share and learn in the Docker community.

Defining container placement in Swarm


(Samattridge) #1

Hi there. I’m struggling to find information regarding the placement of containers within a Swarm cluster. I am testing with Docker 1.13rc6 and trying to get things working using a docker-compose file. Basically, I have found the ‘constraint’ keyword and can utilize node labels to define which servers can be used for which services but I can’t find a way of telling Swarm to prefer to spread the containers over several servers rather than just dumping everything on one. It sometimes puts spreads the containers out but it isn’t guaranteed.

I know about the ‘global’ mode but I would like something similar to what Rancher can do (https://docs.rancher.com/rancher/v1.2/en/cattle/scheduling/) where you can define hard and soft rules for container placement. Is this possible using Swarm mode or is global the only thing that will help me here?

I hope I’ve explained myself clearly but if further clarification is required let me know.

Cheers,
Sam


(Tobias Gesellchen) #2

Do you mean something like below as described at https://docs.docker.com/engine/swarm/services/#specify-service-placement-preferences-placement-pref

$ docker service create \
  --replicas 9 \
  --name redis_2 \
  --placement-pref 'spread=node.labels.datacenter' \
  redis:3.0.6

(Junius) #3

Beside the placement-pref, you could also use the placement constraint.