Docker Swarm
Estimated reading: 5 minutes 23 views

🐳 Playing with Manager and Node Statuses in Docker Swarm

🧲 Introduction – Why Managing Node Statuses in Swarm Matters

In Docker Swarm, nodes are the building blocks of your orchestration cluster. Each node plays a distinct roleβ€”either as a manager or a workerβ€”and knowing how to monitor and control their statuses is key to ensuring service reliability, cluster health, and zero-downtime maintenance.

🎯 In this guide, you’ll learn:

  • The roles and responsibilities of manager vs worker nodes
  • How to inspect, promote, demote, and drain nodes
  • Best practices for maintaining node availability and cluster stability

🧠 Node Roles in Docker Swarm

Docker Swarm nodes operate in one of two roles:

πŸ‘‘ Manager Nodes

  • Coordinate the entire swarm
  • Schedule services and manage state
  • Participate in the Raft consensus to elect a Leader
  • Can also run containers (but not recommended in prod)

πŸ”© Worker Nodes

  • Receive tasks from managers and execute them
  • Do not participate in scheduling or cluster decisions

πŸ’‘ Tip: Use odd numbers of manager nodes (3, 5, 7) to maintain quorum and fault tolerance.


πŸ“Š Inspecting Nodes with docker node ls

Run this command from a manager node to list all nodes in the swarm:

docker node ls

πŸ“‹ Key Columns in the Output:

ColumnDescription
πŸ†” IDUnique identifier for the node
πŸ–₯️ HOSTNAMENode’s hostname
πŸ“Ά STATUSCurrent connection status (e.g., Ready, Down)
βš™οΈ AVAILABILITYTask assignment mode: Active, Pause, or Drain
πŸŽ–οΈ MANAGER STATUSShows if node is manager and its role: Leader, Reachable, or Unavailable

πŸ“Œ Sample Output:

ID                            HOSTNAME   STATUS  AVAILABILITY  MANAGER STATUS
ehkv3bcimagdese79dn78otj5 *   node-1     Ready   Active        Leader
46aqrk4e473hjbt745z53cr3t     node-2     Ready   Active        Reachable
a5b2m3oghd48m8eu391pefq5u     node-3     Ready   Active        

πŸ› οΈ Managing Node Availability States

You can manually change how a node accepts or rejects tasks:

πŸ” Availability Modes:

  • βœ… Active – Accepts new tasks (default)
  • ⏸️ Pause – Keeps running tasks but prevents scheduling new ones
  • 🚫 Drain – Migrates running tasks elsewhere; blocks new tasks

πŸ”§ Update Node Availability:

docker node update --availability drain <NODE-ID>
docker node update --availability pause <NODE-ID>
docker node update --availability active <NODE-ID>

⚠️ Use Case: Drain a node before performing maintenance or decommissioning it.


🩺 Checking Manager Health and Leadership

πŸ” Identify the Leader:

docker node ls

Look for Leader in the MANAGER STATUS column.

πŸ”Ž Inspect Manager Reachability:

docker node inspect <NODE-ID> --format "{{ .ManagerStatus.Reachability }}"

Reachability values:

  • βœ… reachable
  • ❌ unreachable
  • β›” unknown

🧯 Handling Manager Node Failures

If a manager becomes unresponsive:

βœ… Recommended Actions:

  • Restart Docker: systemctl restart docker
  • Reboot the machine if necessary
  • Promote another node if quorum is lost
  • Remove the failed manager: docker node demote <NODE-ID> docker node rm <NODE-ID>

πŸ“Œ Keep at least 3 managers (odd number) to preserve Raft quorum and resilience.


⬆️ Promoting and ⬇️ Demoting Nodes

πŸ‘¨β€πŸ’Ό Promote Worker to Manager:

docker node promote <NODE-ID>

πŸ‘· Demote Manager to Worker:

docker node demote <NODE-ID>

βž• Joining New Nodes to the Swarm

πŸ” Get Join Token (from manager):

docker swarm join-token manager
docker swarm join-token worker

βž• Use Join Command (on new node):

docker swarm join --token <TOKEN> <MANAGER-IP>:2377

πŸ“ˆ Monitoring and Maintaining Swarm Nodes

βœ… Swarm Health Checklist:

  • 🧭 Run docker node ls regularly
  • πŸ•΅οΈ Use docker node inspect <NODE-ID> for in-depth info
  • πŸ‘₯ Maintain quorum by keeping a majority of managers online
  • 🌐 Distribute managers across zones for redundancy
  • βš–οΈ Drain managers not meant to run services

πŸ“˜ Summary – Recap & Takeaways

Mastering node and manager operations in Docker Swarm helps you create fault-tolerant, maintainable, and production-ready clusters. Whether you’re scaling out or debugging failures, controlling node states is essential.

πŸ” Key Takeaways:

  • Use docker node ls to track health and roles
  • Actively manage node availability using drain/pause/active modes
  • Promote/demote nodes as needed to maintain quorum
  • Always ensure an odd number of managers for fault tolerance
  • Use drain before performing node maintenance

βš™οΈ Real-World Relevance: Effective node status management ensures cluster uptime, smooth updates, and safe failover handling in real deployments.


❓ FAQ: Manager and Node Statuses in Docker Swarm

❓ How do I find the current leader manager?

➑️ Use docker node ls and check for Leader under the MANAGER STATUS column.


❓ What does Drain mode do?

➑️ Prevents the node from receiving new tasks and migrates existing ones to other active nodes.


❓ How many manager nodes should I run?

➑️ Always use an odd number (3, 5, or 7) to maintain quorum and support failover scenarios.


❓ What should I do if a manager becomes unreachable?

➑️ Try restarting Docker or the node. If it remains unreachable, demote and remove it to maintain cluster stability.


❓ Can manager nodes run containers?

➑️ Yes, but in critical environments, it’s a best practice to drain managers so they only handle orchestration.


πŸš€ Call to Action – Practice Makes Perfect!

Ready to get hands-on?

πŸ§ͺ Try these in your own swarm setup:

  • Run docker node ls to inspect nodes
  • Change availability with docker node update
  • Promote and demote roles using docker node promote/demote
  • Add/remove nodes using docker swarm join and docker node rm

πŸ’‘ Start by draining a manager node, observe behavior, and restore it. Practice failover handling before it’s needed in production!


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

Playing with Manager and Node Statuses in Docker Swarm

Or Copy Link

CONTENTS
Scroll to Top