Vipul Vaibhaw
Vipul Vaibhaw

Reputation: 433

How to create a docker service on a specific node but scale it to other nodes too in the swarm?

I am new to docker and hence I have this naive doubt in my mind. I want a way that whenever I create a service, it gets created on a specific node but if I scale it, it should get scaled to other nodes too present in docker swarm. I know about --mode global and --constraints node.hostname!=node-1. But that does not solve my problem. Let me if my question is unclear, I will try to explain it in a better way.

Upvotes: 1

Views: 3448

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146630

You need to use placement-pref and have two groups, one for the node where you want to run it and then for other nodes in another group.

$ docker service create \
  --replicas 1 \
  --name myservice \
  --placement-pref 'spread=node.labels.main_machine' \
  --placement-pref 'spread=node.labels.extended_machines' \
  <yourimage>

Now your first one would go on main_machine and the scaled ones would go to extended_machines

See the url https://docs.docker.com/engine/reference/commandline/service_create/#specify-service-placement-preferences-placement-pref

Upvotes: 6

Related Questions