Using Docker Swarm
Recommended Setup
These are optional, and you can setup a basic Docker Swarm after installing the necessary tools. For a quick setup, please see:
Below are some recommended settings when setting up a Docker Swarm.
-
Number of nodes
- At least 3 Linux nodes (VMs or physical machines)
- 1 manager node
- 2+ worker nodes
-
Recommended OS
- Ubuntu 20.04+
- CentOS 7+
- Rocky Linux
- AlmaLinux
-
CPU and RAM
- Each node should have minimum 1 CPU and 1GB RAM
- Docker Engine installed (version 20.10+ recommended)
- Static IP or properly configured networking (especially if across machines)
-
Network Requirements
-
All nodes must be reachable over the network
-
Especially on these ports:
2377/tcp
– for cluster management7946/tcp
and7946/udp
– for node communication4789/udp
– for overlay network (VXLAN)
-
No firewalls blocking the required ports between nodes
-
Consistent DNS or
/etc/hosts
entries for node name resolution (if no DNS)
-
-
User & Access
- SSH access between nodes (especially for setup convenience)
- User with sudo privileges on all nodes
Tools
-
Install Docker:
curl -fsSL https://get.docker.com | bash
sudo usermod -aG docker $USER -
Enable and start Docker:
sudo systemctl enable docker
sudo systemctl start docker -
Install Docker Compose plugin:
For Ubuntu/Debian:
sudo apt-get update
sudo apt-get install docker-compose-pluginFor CentOS/RHEL:
sudo yum install docker-compose-plugin
-
Verify installation
docker compose version
Docker Swarm with Multiple Nodes
-
On the intended manager node, initialize the swarm:
docker swarm init
-
Optional: Bind it to a specific IP (recommended in multi-node labs):
docker swarm init --advertise-addr <MANAGER-IP>
-
Get the join command:
docker swarm join-token worker
-
On the worker node, run the output command (something like):
docker swarm join --token SWMTKN-xxxx <MANAGER-IP>:2377
-
To verify, run
docker stack deploy
on a manager node.docker info | grep 'Swarm'
Expected output if it's a manager:
Swarm: active
Is Manager: trueIf it shows
inactive
, orIs Manager: false
, you're not on the right node.
Docker Swarm with One Node
A few notes:
- A single-node swarm works just like a multi-node one (for testing).
- You can run both manager and worker roles on the same machine.
Ideal for testing features like:
docker stack deploy
docker service ls
- Rolling updates, constraints, placement preferences (in limited form)
Steps:
-
Initialize the swarm:
docker swarm init
This makes your local machine the manager node, and it's automatically part of the swarm.
Swarm initialized: current node (abcdefgh12345) is now a manager.
-
Verify it’s active:
docker info | grep Swarm
You should see:
Swarm: active
Is Manager: true
Optional but Useful Tools
- Visualizers like Docker Swarm Visualizer
- Portainer (lightweight web UI for Docker Swarm)