The DevOps 2.1 Toolkit:Docker Swarm
上QQ阅读APP看书,第一时间看更新

Failover

Fortunately, failover strategies are part of Docker Swarm. Remember, when we execute a service command, we are not telling Swarm what to do but the state we desire. In turn, Swarm will do its best to maintain the specified state no matter what happens.

To test a failure scenario, we'll destroy one of the nodes:

docker-machine rm -f node-3

Swarm needs a bit of time until it detects that the node is down. Once it does, it will reschedule containers. We can monitor the situation through service ps command:

docker service ps go-demo

The output (after rescheduling) is as follows (ID is removed for brevity):

As you can see, after a short period, Swarm rescheduled containers among healthy nodes (node-1 and node-2) and changed the state of those that were running on the failed node to Shutdown. If your output still shows that some instances are running on the node-3, please wait for a few moments and repeat the service ps command.