So I have a similar issue with compose version 3.6. What I’m trying to achieve is to only deploy either service A or B depending on the label value applied to the node. What’s happening is both services are getting deployed (or one is and the second one fails due to port usage).
- node.labels.faces == cpu
- node.labels.faces == gpu
On my single node I have defined a label as follows
# docker node inspect swarm-manager --pretty
Is this configuration even possible? I want swarm to only deploy the GPU service when the node has a GPU video card deployed, else run CPU service.
I initially wanted to use global instead of replicated, but I read in another forum that the two are not compatible so I have to use replicated instead.
UPDATE: If I create manually it works as expected
docker node update --label-add faces=cpu swarm-manager
docker service create -d --name serviceA --constraint node.labels.faces==cpu -p 8888 --mode global serviceA:v1
docker service create -d --name serviceB --constraint node.labels.faces==gpu -p 8888 --mode global serviceB:v1
# docker service ls | grep service
c30y50ez605p serviceA global 1/1 service:v1 *:30009->8888/tcp
uxjw41v42vzh serviceB global 0/0 serviceB:v1 *:30010->8888/tcp
You can see that the service created with CPU constraint worked and the service with GPU was not instantiated (in pending state).