0

This is my docker-stackk.yaml file.

# cat docker-stack.yml 
version: "3.4"
services:

  redis:
    image: redis:alpine
    ports:
      - "6379"
    networks:
      - frontend
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

networks:
  frontend:

volumes:
  db-data:

I did not specified any constraint.

# docker node ls
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
snbsjfcg8eu6w88oyinsaa2q0 *   infinity   Ready     Active         Reachable        20.10.8
bi2iblsfma9dno4thvcpetc29     rockpi     Ready     Active         Leader           20.10.8
d5nk1bgdpmo05u1pdlbtxppem     rockpix    Ready     Active                          19.03.8

if you see above rockpix is worker node. and infinity is manager.

but when I started the stack the container started on manager node instead of worker node.

# docker stack ps redis-stack
ID             NAME                  IMAGE          NODE       DESIRED STATE   CURRENT STATE           ERROR     PORTS
zvd9dyx10ro9   redis-stack_redis.1   redis:alpine   infinity   Running         Running 2 minutes ago  
0

A manager is able to run containers just as workers do. To prevent workloads from running on the manager, you need to include a constraint. This is different from the kubernetes model where the managers are tainted and you include a toleration to run on managers.

version: "3.4"
services:

  redis:
    image: redis:alpine
    ports:
      - "6379"
    networks:
      - frontend
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure
      # add the below constraint
      placement:
        constraints:
          - "node.role==worker"

networks:
  frontend:

volumes:
  db-data:

For more on the placement policies and constraints, see:

2
  • I see, thanks, However in that case can we have 2 replicas 1 on manager and 1 on worker ?
    – Chang Zhao
    Sep 26 at 9:21
  • 1
    @ChangZhao you'd need different constraints for that. But consider what you want to happen if a node goes down when you define those constraints. And with only one manager, if the manager itself goes down, no tasks will be rescheduled.
    – BMitch
    Sep 26 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.