can we deploy a container into a specific node in a docker swarm

jojo picture jojo · Apr 13, 2016 · Viewed 18.3k times · Source

I have a docker swarm cluster, it contains 1 master 3 nodes. When we deploy a container through swarm master, e.g with the below command

docker -H tcp://<master_ip>:5001 run -dt --name swarm-test busybox /bin/sh

Swarm will auto pick a node and deploy my container. Is there a way to hand pick a node? e.g I want to deploy a container in node 1.

Answer

Erik Dannenberg picture Erik Dannenberg · Apr 13, 2016

Take a look at the Swarm filter docs. You can set various constraints on what node Swarm should pick for any given container. For your case try something like:

docker run ... -e constraint:node==node1 ...

This would start the container on node1.