Docker Community Forums

Share and learn in the Docker community.

1.12: How to distribute a service to only nodes with a specific label

(Raarts) #1

Is that what docker service --label is for? Can anybody explain what the --label does?

(Dvohra) #2

Which docker command has --label?

(Brandon Mitchell) #3

You can launch your various docker engines with labels of your choosing and then use those labels in constraints when launching containers in a swarm. So, for example:

dockerd --label region=east --label env=prod ...

And then when running containers in your swarm:

docker run -it -e constraint:region==east busybox

The container will only launch on a node with that label. See the swarm filter docs for more details.

(Raarts) #4

The command is docker service

(Raarts) #5

Thanks. If this actually works that’s great. I’m going to test it out for sure.