Docker compose + swarm: pointing compose to a specific swarm node

2,024 views
Skip to first unread message

Luca Gioppo

unread,
Jun 2, 2015, 5:12:20 PM6/2/15
to docke...@googlegroups.com
I've seen the short demo in the docs (http://blog.docker.com/2015/02/orchestrating-docker-with-machine-swarm-and-compose/).
I would like to know if is possible to choose on which swarm node docker-compose will make the deploy.
Is there some additional flags to add to the docker-compose up to instruct swarm to send the execution on a specific node?  Do we have some control or is swarm that decides randomly (and in that case with what policy)?
Thanks
Luca

Andrea Luzzardi

unread,
Jun 2, 2015, 6:43:07 PM6/2/15
to Luca Gioppo, docke...@googlegroups.com
Swarm schedules containers based on a placement strategy: https://github.com/docker/swarm/tree/master/scheduler/strategy

There are currently 3: spread (default), binpack and random.

The strategy is an option of the Swarm daemon and affects *all* containers (including containers sent by Compose).

- al

--
You received this message because you are subscribed to the Google Groups "docker-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to docker-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luca Gioppo

unread,
Jun 4, 2015, 4:37:46 AM6/4/15
to docke...@googlegroups.com
So there is no way to send containers to a precise node or set of nodes with swarm.
Any chances of having it implemented in the near future?

The business case is that I could have some nodes dedicated to specific customers and I could want to deploy containers just on those.

Also how does this live with the constraints that in the docs is stated that compose will deploy all in the same host since linked containers can live just on the same host for actual network limitations?
Is swarm taking ownership of that?

Better explain if a docker-compose-yml defines 3 containers linked together and I do a compose up against swarm will the 3 container be placed in the same node by swarm automatically since they are linked and would not work spread?

Is there a way to manage clusters of different customers at the moment or this calls for different swarm master?
Thanks
Luca

Leen Besselink

unread,
Jun 4, 2015, 7:38:30 AM6/4/15
to docke...@googlegroups.com
Hi,

I'm not a developer of compose or swarm, but I do know that Swarm supports constraints:

__

In order to meet the specific requirements of each container, their placement can be fine-tuned using constraints. For instance, Swarm can be instructed to run MySQL on a host with flash storage:

docker run -d -e constraint:storage==ssd mysql

Constraints operate on Docker daemon labels. To make the previous example work, Docker must be started with the –label storage=ssd option.

More advanced expressions are also supported:

docker run --rm -d -e constraint:node!=fed*
docker run --rm -d -e constraint:node==/ubuntu-[0-9]+/

https://blog.docker.com/2015/02/scaling-docker-with-swarm/

More documentation:

https://docs.docker.com/swarm/scheduler/filter/#constraint-filter

__

If compose supports that I don't know, but it looks to me like it might already be supported in 1.3:

https://github.com/docker/compose/issues/1379

https://github.com/docker/swarm/pull/673

Aanand Prasad

unread,
Jun 4, 2015, 7:51:48 AM6/4/15
to le...@consolejunkie.net, docke...@googlegroups.com
Correct. Compose lets you set custom environment variables, and therefore Swarm constraints and affinity. For example:

db:
  image: postgres
  environment:
    - "constraint:node==node-1"

As of Swarm 0.3 and Compose 1.3, this is done with custom labels instead:

db:
  image: postgres
  labels:
    - "constraint:node==node-1"

Luca Gioppo

unread,
Jun 4, 2015, 5:48:42 PM6/4/15
to docke...@googlegroups.com
Thank that was what I was looking for.
Luca
Reply all
Reply to author
Forward
0 new messages