Preparation
I used three VM nodes for this home lab project with 4 Cores 4GB Memory and 20GB for the containers storage with operating systems Rocky Linux 9.5 with Docker community edition v28.2.2.
| Node Hostname | vCPU | Memory | Storage | PrivateNet |
|---|---|---|---|---|
| hmlab01swarm01 | 4 Core | 4GB | 20GB | 172.16.0.111 |
| hmlab01swarm02 | 4 Core | 4GB | 20GB | 172.16.0.112 |
| hmlab01swarm03 | 4 Core | 4GB | 20GB | 172.16.0.113 |
All operations use the
rootuser, be careful when running commands!
In this step execution on all nodes
Optional: Set SElinux to permissive mode for dev environments
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
Set static hostname
Set Up environment
node_01=hmlab01swarm01
node_02=hmlab01swarm02
node_03=hmlab01swarm03
node_IP01=172.16.0.111
node_IP02=172.16.0.112
node_IP03=172.16.0.113
then add static hostname in /etc/hosts for all nodes.
cat <<EOF > /etc/hosts
$NODE_IP01 $NODE_01
$NODE_IP02 $NODE_02
$NODE_IP03 $NODE_03
EOF
Add Repository and Install Docker
dnf install -y dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Set
cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
systemctl restart docker.service
systemctl enable docker.service
Bootsraping cluster
First execute only in first manager node
docker swarm init --advertise-addr 172.16.0.111 --force-new-cluster

To add other manager ndoe exec this command that we have before with docker swarm join-token manager in first manager node.
docker swarm join --token SWMTKN-1-04x40p3y8w72nv7a3merg1ee4ya4t6r3ra379gv7hv79udt0ho-8d18zrgpy5elj3f69i7rvz8tf 172.16.0.111:2377
