Hi,
First of all, I’m pretty new to Docker, and tried to look for information on this forum, but found very different answers and none of them worked for me
I would like to create a Docker cluster for running services in a failover option.
My current setup is the following:
HOSTNAME STATUS AVAILABILITY MANAGER
DOCKER-BKP Ready Active Reachable
DOCKER-MANAGER Ready Drain Leader
DOCKER-PROJ_A Ready Active
DOCKER-PROJ_B Ready Active
My task would be to run the service SRVC-PROJ_A on DOCKER-PROJ_A preferably, and if it fails (Server turns off, or not reachabel) the Swarm should start a Replica/Copy on DOCKER-BKP.
The task is the same with SRVC-PROJ_B. IF DOCKER-PROJ_B fails, a Replica/Copy should start on DOCKER-BKP.
No PROJ_A service should run on node PROJ_B and neither PROJ_B service on node PROJ_A.
If a preferred node is active again, no automatic “Role drain back” should run. We want to put back the “service” manually to the desired node, because no service can run in two instances. It has to be stopped first.
I found a thread where somebody said I can set this with Node Labels & --placement-pref flag.
The first flag should be the desired node, and the second one, is where the service can spread.
These are my labels:
HOSTNAME LABELS
DOCKER-BKP PROJ_A PROJ_B
DOCKER-PROJ_A PROJ_A PROJ_A-MASTER
DOCKER-PROJ_B PROJ_B PROJ_B-MASTER
And my commands:
> docker service create --replicas 1 --replicas-max-per-node 1 --placement-pref "spread=node.labels.PROJ_A-MASTER" --placement-pref "spread=node.labels.PROJ_A" --update-order stop-first --rollback-order stop-first --network host -p 8080:80 --name SRVC-PROJ_A nginx:latest
>
> docker service create --replicas 1 --replicas-max-per-node 1 --placement-pref "spread=node.labels.PROJ_B-MASTER" --placement-pref "spread=node.labels.PROJ_B" --update-order stop-first --rollback-order stop-first --network host -p 8081:80 --name SRVC-PROJ_B nginx:latest
Unfortunately it always starts the service on a different node, and doesn’t even bother about the labels.
Sometimes it starts SRVC-PROJ_A on DOCKER-PROJ_B for example, but it doesn’t even have that label.
I also found that Docker starts the services in the “Emptiest” mode, so the node with the least running services is where the next service starts, but it’s not true neither, because last time, it started both services on DOCKER-PROJ_A, even though both nodes DOCKER-BKP & DOCKER-PROJ_B was empty and active.
Is there a way I can make it work, or Docker is not capable for my use case?
Thx, for your help!