Docker swarm & compose - placement constraints ignored

Hello there,

We have the problem that placement constraints are ignored on our Swarm cluster. Here is the situation:

  • we have 2 nodes, manager and worker
  • each node has a user defined label set: node.labels.app_role=wproc, node.labesl.app_role=wweb

We want to send the containers that run web apps to the one labeled wweb and the rest to wproc. On the docker-compose.yml file we have

services:
  webapp:
    image:...
    command: ...
    deploy:
      replicas: 2
      restart_policy:
        condition: any
        max_attempts: 5
      update_config:
        parallelism: 2
        delay: 10s
      placement:
        constraints: [node.labels.app_role==wweb]
    networks:
      - backend
      - frontend

  procworker:
    image: ...
    command: ...
    deploy:
      replicas: 1
      restart_policy:
        condition: any
        max_attempts: 5
      update_config:
        parallelism: 2
        delay: 10s
      placement:
        constraints: [node.labels.app_role==wproc]
    networks:
      - backend

The 2 nodes has this information under the Labels: section,

host:~/$ docker node inspect xxx-web-001 --pretty | grep "node.labels"
 - node.labels.app_role=wweb
host:~/$ docker node inspect xxx-proc-001 --pretty | grep "node.labels"
 - node.labels.app_role=wproc
host:~/$

This is pretty much all what we have. What I am missing to make this work?

Thanks!

What is the version of your docker-compose file? I currently use version 3.2 but instead of using labels I use the “node.role” option (manager | worker)

Hi knowral,

Try this:
Use “Constraint”
Instead of “Constraints”

Regards,
Makunii