Step 1 — Init the Swarm on MASTER
On the MASTER Pi, run:
Run on MASTER
$ docker swarm init --advertise-addr 192.168.0.23
Replace 192.168.0.23 with the actual IP of your MASTER Pi (from the previous step). The output will look like this:
Expected output
Swarm initialized: current node (jg3z8p6rei7yk1d18disx0j5h) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1gp7povi99cvtn4vdcor1ehoi9l2fnkbbgasxl8sibp5osyrhx-3l6yptd5h58vssjbr52xvl9pt 192.168.0.23:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Copy the join command — you'll need to paste it on each SLAVE node in the next step. The token is unique to your swarm.
Step 2 — Join SLAVE Nodes
On each SLAVE (SLAVE1, SLAVE2, SLAVE3), paste and run the join command from the output above:
Run on SLAVE1, SLAVE2 and SLAVE3
$ docker swarm join \
--token SWMTKN-1-1gp7povi99cvtn4vdcor1ehoi9l2fnkbbgasxl8sibp5osyrhx-3l6yptd5h58vssjbr52xvl9pt \
192.168.0.23:2377
# Expected output:
This node joined a swarm as a worker.
Step 3 — Verify the Cluster
Back on the MASTER, verify all 4 nodes are in the swarm:
Run on MASTER
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
jg3z8p6rei7yk * MASTER Ready Active Leader
abc456def789 SLAVE1 Ready Active
ghi012jkl345 SLAVE2 Ready Active
mno678pqr901 SLAVE3 Ready Active
Check Swarm Status with docker info
Verify swarm is active
$ docker info | grep -A 5 Swarm
Swarm: active
NodeID: jg3z8p6rei7yk1d18disx0j5h
Is Manager: true
ClusterID: 1pf6vk1h3zx0b2dxbf2i0cg1v
Managers: 1
Nodes: 4
Official documentation: docs.docker.com — docker swarm init