Home > Net >  Limit deployment of certain services with docker swarm/compose
Limit deployment of certain services with docker swarm/compose

Time:06-30

I have this compose file:

version: "3.3"

services:
  icecc-scheduler:
    build: services/icecc-scheduler 
    restart: unless-stopped
    network_mode: host

  icecc-daemon:
    build: services/icecc-daemon    
    restart: unless-stopped
    network_mode: host

I then have a docker swarm configured with 5 machines, the one I'm on is the manager. When I deploy my stack I want the icecc-daemon container to be deployed to all nodes in the swarm while the icecc-scheduler is only deployed once (preferably to the swarm manager). Is there any way to have this level of control with docker compose/stack/swarm?

CodePudding user response:

Inside docker swarm, you can achieve desired behaviour by using placement constraints.

To achieve the service is deployed only to the manager node the constraint should be: - "node.role==manager"

To achieve the service is only deployed once you can refer to the

deploy:
  mode: replicated
  replicas: 1

section. This will make your service run on one replica only inside the whole swarm cluster.

To achieve service is deployed exactly as one container per swarm node, you can use:

deploy:
  mode: global

More information on the parameters on official docs

  • Related