Skip to main content
In this step-by-step guide, you will learn how to bootstrap a resilient Docker Swarm cluster on CentOS 7.6, manage node roles, control availability, and gracefully remove nodes. By the end of this tutorial, you’ll have a three-node swarm (one manager, two workers) and know how to:
  1. Initialize the swarm
  2. Join worker nodes
  3. Promote and demote managers
  4. Drain and reactivate nodes
  5. Remove nodes from the cluster
This tutorial assumes all nodes can resolve each other by hostname, have open swarm ports, and run Docker Engine v19.03.8 or later.
  • Three CentOS 7.6 servers (managerone, workerone, workertwo)
  • 2 CPU cores and 4 GB RAM each
  • Hostname resolution (e.g., via /etc/hosts or DNS)
  • Open ports:
    • TCP 2377 for cluster management
    • TCP/UDP 7946 for node discovery
    • UDP 4789 for overlay networking
  • Docker Engine installed and running

System Overview

1. Initialize the Swarm on managerone

  1. Confirm Swarm is inactive:
  2. Initialize with the manager’s advertise address:
    After initialization, note the worker join command output:

2. Add the First Worker (workerone)

On workerone, run the join command displayed by the manager:
Back on managerone, verify:

3. Add the Second Worker (workertwo)

3.1. Prepare workertwo

Ensure OS, CPU, memory, Docker version, and connectivity:

3.2. Retrieve and Run the Join Token

On managerone, print the worker join command:
Copy the docker swarm join --token … line and execute it on workertwo. Then confirm on managerone:

4. Promote a Worker to Manager

  1. List current nodes:
  2. Promote workerone:
  3. Verify the new manager status:
  4. (Optional) Inspect workerone in detail:

5. Demote a Manager back to Worker

If you need to revert workerone to a purely worker role:

6. Drain and Reactivate a Node

To prevent new tasks from scheduling on workerone:
When you’re ready to allow tasks again:

7. Remove a Node from the Swarm

  1. Drain workerone:
  2. Attempt removal (will fail if the node is still up):
  3. On workerone, leave the swarm:
  4. Back on managerone, remove the node:
Congratulations! You’ve successfully created, scaled, and managed a Docker Swarm cluster on CentOS 7.6.

References and Further Reading

Watch Video