Docker lab/version note: use supported Linux-container tools and patched images. Check version compatibility before running the examples. Docker, Swarm and platform-specific deployment steps were not tested live.
What this guide covers
Docker Swarm schedules container tasks across Docker hosts. This guide uses one manager to control the cluster and two workers to run applications. A single manager is a learning setup, not a highly available design.
Before you start
Use three fresh Ubuntu 24.04 hosts: manager1 at 192.168.50.21, worker1 at .22 and worker2 at .23. Replace the example addresses consistently. Give each host a unique name, stable private IP, synchronized time and sudo access.
Allow TCP 2377 to the manager from members, TCP/UDP 7946 and UDP 4789 between members. Do not expose these ports publicly. Keep SSH access when changing firewall rules.
Step 1: Install Docker on each host
Run on all three machines:
sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
. /etc/os-release
printf 'deb [arch=%s signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu %s stable\n' \
"$(dpkg --print-architecture)" "$VERSION_CODENAME" \
| sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker
sudo docker version
sudo docker info
Use the supported Docker repository for your actual OS version. Confirm the daemon is running with sudo docker info.
Step 2: Initialize the manager
Run on manager1 only:
sudo docker swarm init \
--advertise-addr 192.168.50.21 \
--data-path-addr 192.168.50.21
sudo docker swarm join-token worker
Run the printed worker join command on worker1 and worker2, using their reachable private addresses. The join token is a credential: do not publish it. Do not run swarm init on the workers.
Step 3: Check membership and worker placement
Back on the manager:
sudo docker node ls
sudo docker node update --availability drain manager1
sudo docker node inspect worker1 --pretty
sudo docker node inspect worker2 --pretty
All nodes should be Ready. Draining the manager prevents ordinary tasks from being placed there, but it remains the only management node. Use worker nodes for the test applications.
Check the result
Check worker communication with a test overlay-network service before deploying an application stack. Losing the only manager prevents normal management and scheduling operations; two workers do not fix that limitation.
Conversation
0 commentsNo comments yet. Start the conversation below.