Defining container placement in Swarm

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 ( 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.


Do you mean something like below as described at

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

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