I am running a Docker swarm across 10 different host/servers/machines all labeled differently e.g. nginx_1 nginx_2 nginx_3 nginx_4 app_1 app_2 app_3 app_4 testing_1 testing_2
Using Docker swarm constraints is there a way to specify which node a service can run on using a label and wildcard which would tel the service to run on any node with a label starting with nginx e.g.
--constraint 'node.labels.name ==nginx*'
We can't use wildcards in --constraint
for the time being.
You could label all your nginx nodes with a new label, for instance:
docker node update --label-add type=web node1
docker node update --label-add type=web node2
...
And use --constraint
to create your nginx service on web
labeled nodes only:
docker service create \
--name nginx \
--constraint 'node.labels.type == web' \
nginx