Search code examples
dockerdocker-swarm

How do I move a container from one node to another?


I run:

docker service create --replicas 2 --name search --publish 9200:9200 elasticsearch:2

In my nodes: docker node ls

vbgqoejyrxbjxtt9bx7pa0qxl     nodo1             Ready               Active                                  19.03.2
dg75e1scg8fgjxdk6hb8fohii *   nodo2     Ready               Active              Leader              18.09.7

When node2 is restarted, the two services go to node1, and when node1 is ready again, the two services stay on node2 How can I move the service to the previous node? In my case I have used:

docker service update --force search

Solution

  • One of the purposes of Docker-Swarm and other orchestrators (like Kubernetes) - is that they cover all underlaying structure, like nodes, so you don't have to deal with manual scheduling to particular node.

    So if Swarm has moved your application to particular node, that's because it's "convenient for Swarm" and if he really needs to rebalance nodes, then he will do so. But until Swarm has a strong reason to do so, everything stays same.

    New applications most probably will be balanced between 2 nodes