Drain a node on the swarm (original) (raw)
In earlier steps of the tutorial, all the nodes have been running with Active
availability. The swarm manager can assign tasks to any Active
node, so up to now all nodes have been available to receive tasks.
Sometimes, such as planned maintenance times, you need to set a node to Drain
availability. Drain
availability prevents a node from receiving new tasks from the swarm manager. It also means the manager stops tasks running on the node and launches replica tasks on a node with Active
availability.
Important
Setting a node to
Drain
does not remove standalone containers from that node, such as those created withdocker run
,docker compose up
, or the Docker Engine API. A node's status, includingDrain
, only affects the node's ability to schedule swarm service workloads.
- If you haven't already, open a terminal and ssh into the machine where you run your manager node. For example, the tutorial uses a machine named
manager1
. - Verify that all your nodes are actively available.
- If you aren't still running the
redis
service from therolling update tutorial, start it now: - Run
docker service ps redis
to see how the swarm manager assigned the tasks to different nodes:
In this case the swarm manager distributed one task to each node. You may see the tasks distributed differently among the nodes in your environment. - Run
docker node update --availability drain <NODE-ID>
to drain a node that had a task assigned to it: - Inspect the node to check its availability:
The drained node showsDrain
forAvailability
. - Run
docker service ps redis
to see how the swarm manager updated the task assignments for theredis
service:
The swarm manager maintains the desired state by ending the task on a node withDrain
availability and creating a new task on a node withActive
availability. - Run
docker node update --availability active <NODE-ID>
to return the drained node to an active state: - Inspect the node to see the updated state:
When you set the node back toActive
availability, it can receive new tasks:- during a service update to scale up
- during a rolling update
- when you set another node to
Drain
availability - when a task fails on another active node
Next, you'll learn how to use a Swarm mode routing mesh