Adding or removing nodes in Docker Swarm is extremely straightforward—one of the major selling points of Swarm is its ease of scaling the control plane and worker pool. Here’s how it works in practice:
1. Preparing Your Tokens
When you initialize the Swarm on the first manager, Docker generates two join-tokens: one for managers, one for workers. You can retrieve them at any time:
bash
# On any manager node:
docker swarm join-token manager # shows the token to add a manager
docker swarm join-token worker # shows the token to add a worker
Keep these tokens handy (they’re long strings).
2. Adding a Node
a) Add a Worker
SSH into the new machine you want to join as a worker.
Run the join command with the worker token and manager’s address:
You should see This node joined a swarm as a worker.
b) (Optionally) Promote to Manager
If you need this new node to be a manager:
bash
# On an existing manager
docker node promote <NODE_ID_or_NAME>
3. Removing a Node
a) Graceful Leave (from the node itself)
On the node you want to remove (whether worker or manager):
bash
docker swarm leave
If it’s a manager, add --force to leave even if it’s the leader:
bash
docker swarm leave --force
b) Forcible Removal (from a manager)
If the node is gone or unresponsive, you can prune it from the cluster:
bash
# On a manager
docker node rm <NODE_ID_or_NAME>
This cleans up the Swarm’s state.
4. How Swarm Rebalances Your Services
As soon as you add a node, Swarm’s scheduler sees the extra capacity and can place new service tasks there (if you scale up or deploy a new stack).
When you remove a node, Swarm automatically reschedules any running tasks that were on that node onto remaining nodes, preserving your desired replica count.
5. Tips & Gotchas
Tokens: Treat them like passwords. If you suspect they’re compromised, rotate them:
bash
# On a manager
docker swarm update --autolock=true # enables auto-locking (forces rekey)
Manager Quorum: Always keep an odd number of managers (3 or 5). Don’t remove a manager without demoting it first:
bash
docker node demote <MANAGER_NODE>
Networking: Ensure new nodes can reach existing managers on ports 2377, 7946, 4789 (TCP/UDP) for clustering and overlay networking.
Stateful Services: If you’re using shared storage (NFS, EFS, etc.), make sure the new nodes mount the same volumes in the same paths.
Conclusion
– Adding a new worker or manager is a single CLI command away.
– Removing is equally simple (either leave from the node, or docker node rm from a manager).
– Swarm’s scheduler immediately adapts, rebalancing workloads to match your desired state.
Docker Swarm makes horizontal scaling (up and down) almost invisible—perfect for dev, test, or even production clusters where you want frictionless node management. 🚀
User
what are the computing resources required for running a docker swarm manager
Assistant
Here’s a guideline on the kind of resources you’ll want to dedicate to each Docker Swarm manager node. In a small 3-node dev cluster the requirements are modest—but it’s good to understand how they grow with cluster size and workload.
1. CPU & Memory
A Swarm manager runs the Docker Engine plus the Raft consensus service, the scheduler, and the state store. CPU and RAM needs scale with:
• Number of total nodes
• Number of services and tasks
• Rate of “churn” (how often you add/remove services or scale replicas)
Scale Category
CPU
RAM
Notes
Tiny (≤ 10 nodes)
1–2 vCPUs
2–4 GB
Dev/test, very light churn
Small (10–100 nodes)
2–4 vCPUs
4–8 GB
Typical production Small/Medium Swarm
Medium (100–300)
4–8 vCPUs
8–16 GB
Higher availability, moderate churn
Large (300–500+)
8–16 vCPUs
16–32 GB
Heavy churn, many services, near the tested ~1000-node limits
Tip: If your managers ever spike in CPU or RAM (you can watch dockerd via top or docker stats), it’s a sign you need to vertically scale your managers or reduce churn.
2. Storage
– Disk Type: SSD/NVMe strongly recommended
– Disk Size:
• OS + Docker + Raft logs: ~10–20 GB
• Docker images & local volumes (optional): +size of your images/volumes
– I/O Considerations:
• Raft writes are small but frequent. Fast fsync performance is critical.
• If you use local volumes on managers (not best practice for stateful services), ensure you have enough IOPS.
3. Network
– Latency: < 10 ms between managers (all in one rack or AZ)
– Bandwidth:
• 1 Gbps is fine for most dev/test and small production clusters
• 10 Gbps if you’re running very chatty services or high-volume data across overlay networks
– Open Ports:
• TCP 2377 (cluster management)
• TCP/UDP 7946 (gossip)
• UDP 4789 (overlay VXLAN)
4. Operating System & Kernel
– Modern Linux distro (Ubuntu 20.04+, RHEL 8+, Debian 11+, etc.)
– Docker Engine (latest Stable)
– Kernel ≥ 4.15 for optimal overlay network performance
– Swarm auto-lock (optional): requires unlocking on reboot, so plan for secure key-storage or KMS integration
5. High-Availability Recommendations
When you have 3 managers:
Keep an odd number (3 or 5) to maintain quorum.
Distribute them across failure domains (different racks/AZs), but keep latency low.
Monitor CPU, RAM, disk I/O on your managers—if any one node becomes a bottleneck, Swarm operations (deployments, scaling) slow down for the entire cluster.
6. A Sample “Small Production” Manager Spec
For a stable, small-scale production Swarm (50–100 nodes):