Home Explore Blog Models CI



docker

1st chunk of `content/manuals/engine/swarm/swarm-tutorial/drain-node.md`
6a88dbf33d156824c7dca9c91026f04c7aab1327ce4a503a000000010000095d
---
description: Drain nodes on the swarm
keywords: tutorial, cluster management, swarm, service, drain, get started
title: Drain a node on the swarm
weight: 80
notoc: true
---

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.

>
> Setting a node to `Drain` does not remove standalone containers from that node,
> such as those created with `docker run`, `docker compose up`, or the Docker Engine
> API. A node's status, including `Drain`, only affects the node's ability to schedule
> swarm service workloads.

1.  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`.

2.  Verify that all your nodes are actively available.

    ```console
    $ docker node ls

    ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
    1bcef6utixb0l0ca7gxuivsj0    worker2   Ready   Active
    38ciaotwjuritcdtn9npbnkuz    worker1   Ready   Active
    e216jshn25ckzbvmwlnh5jr3g *  manager1  Ready   Active        Leader
    ```

3.  If you aren't still running the `redis` service from the
    [rolling update](rolling-update.md) tutorial, start it now:

    ```console
    $ docker service create --replicas 3 --name redis --update-delay 10s redis:7.4.0

    c5uo6kdmzpon37mgj9mwglcfw
    ```

4.  Run `docker service ps redis` to see how the swarm manager assigned the
tasks to different nodes:

    ```console
    $ docker service ps redis

    NAME                               IMAGE        NODE     DESIRED STATE  CURRENT STATE
    redis.1.7q92v0nr1hcgts2amcjyqg3pq  redis:7.4.0  manager1 Running        Running 26 seconds
    redis.2.7h2l8h3q3wqy5f66hlv9ddmi6  redis:7.4.0  worker1  Running        Running 26 seconds
    redis.3.9bg7cezvedmkgg6c8yzvbhwsd  redis:7.4.0  worker2  Running        Running 26 seconds
    ```

    In this case the swarm manager distributed one task to each node. You may

Title: Draining a Node in a Docker Swarm
Summary
This section explains how to drain a node in a Docker Swarm. Draining a node prevents it from receiving new tasks and migrates existing tasks to active nodes. The tutorial guides you through setting a node to `Drain` availability, observing task redistribution, and verifying the change using `docker node ls` and `docker service ps` commands. It also clarifies that draining a node only affects swarm service workloads and not standalone containers.