Enissay
Enissay

Reputation: 4953

Docker deploy swarm instance on specific node matching instance index

Using docker swarm, I am trying to deploy N instances of my app on N nodes in a way that each app is deployed on the node with the corresponding index. E.g.: app1 must be deployed on node1, app2 on node2, ...

The bellow is not working as it complains Error response from daemon: rpc error: code = Unknown desc = value 'node{{.Task.Slot}}' is invalid.

Any suggestion how to achieve this ?

I also have the impression, in a long shot, to use something with labels but I cannot wrap my head over it yet. Anyhow please advise.

version: "3.8"

services:

  app:
    image: app:latest
    hostname: "app{{.Task.Slot}}"
    networks:
      - app-net
    volumes:
      - "/data/shared/app{{.Task.Slot}}/config:/app/config"
    deploy:
      replicas: 5
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: any
      placement:
        constraints:
          - "node.hostname==node{{.Task.Slot}}"   <========= ERROR

Upvotes: 0

Views: 317

Answers (1)

Chris Becke
Chris Becke

Reputation: 36121

Service template parameters are documented as only resolving in:

  • the hostname: directive
  • for volume definitions
  • in labels.
  • environment variables.

Placement preference / constraints is not supported, but would be brilliant as it would allow simple deployments of Minio, etcd, consul and other clustered services where you need to pin replicas to nodes.

Upvotes: 0

Related Questions