Docker 群约束通配符

Docker swarm constraint wildcards

我运行正在 Docker 集群跨越 10 个不同的 host/servers/machines 所有标签都不同,例如 nginx_1 nginx_2 nginx_3 nginx_4 app_1 app_2 app_3 app_4 testing_1 testing_2

使用 Docker swarm constraints 是否有一种方法可以指定服务可以 运行 使用标签和通配符的节点,该标签和通配符会将服务发送到任何节点上的 运行以 nginx 开头的标签,例如

--constraint 'node.labels.name ==nginx*' 

我们暂时不能在--constraint中使用通配符。

您可以label all your nginx nodes with a new label,例如:

docker node update --label-add type=web node1
docker node update --label-add type=web node2
...

并且 use --constraint to create your nginx service 仅在 web 标记的节点上:

docker service create \
--name nginx \
--constraint 'node.labels.type == web' \
nginx