1

So I have an issue with compose version 3.6 and deploying swarm services. 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).

 serviceA:
    image: serviceA:v1
    deploy:
      mode: global
      restart_policy:
        condition: on-failure
      placement:
        constraints:
          - node.labels.faces == cpu
    networks:
      - mynet
    ports:
      - "8888:8888"

  serviceB:
    image: serviceB:v1
    deploy:
      mode: global
      restart_policy:
        condition: on-failure
      placement:
        constraints:
          - node.labels.faces == gpu
    networks:
      - mynet
    ports:
      - "8888:8888"

On my single node I have defined a label as follows

# docker node inspect swarm-manager --pretty
ID:         0cpco8658ap5xxvxxblpqggpq
Labels:
 - faces=cpu
Hostname:               swarm-manager

Is this configuration even possible? Only the service which has a matching label should be instantiated.

I want to use global instead of replicated because we add additional nodes automatically without going to the master, but I read in another forum that the two might not be compatible.

However, if I create everything manually using CLI 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).

Carl Wainwright
  • 328
  • 5
  • 18

0 Answers0