This example Uses 4 Raspberry Pi Model 3 A+ each with 16Gb Micro SD Card


Headless Install of Raspbian Lite

Base Image Install

Install Raspbian Buster Lite onto Micro SD Card

Download Raspbial Buster Lite from here 

check the SHA-256 hash matches ( sha256sum <filename> then unzip

Insert Micro SD Card and run sudo fdisk -l to identify the micro sd card

Unmount the above device sudo umount /dev/<device name>1

Apply the image sudo dd bs=1M if=<filename>.img of=/dev/<device name>

remove and rensert the sd card to mount it

O/S Configuration

Enable SSH Access by creating an empty file called ssh in the /boot folder

Enable WIFI access by editing the file /etc/wpa_supplicant/wpa_supplicant.conf and setting the contents to :-

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

        ssid="<network ssid>"
        psk="<network password>"

Set host name by editing the file /etc/hosts change raspberrypi to dockerx 

also edit /etc/hostname setting the same hostname

Power Up and Install Docker

Get the ip address of each pi and add this to your hosts file

Install docker on each pi 

curl -fsSL -o && sh

 Allow current user to run docker commands

sudo usermod -aG docker pi

 then reboot

the test docker with

docker run hello-world

Create Docker Swarm

Pi nodes 1 and 2 will become managers with pi nodes 3 and 4 becoming workers

on node1 initialise the swarm

 docker swarm init --advertise-addr

Use the join command on nodes 3 and 4

docker swarm join --token SWMTKN-1-2oa3993czvstgmbonumk4zln1gkt5dja32ssogr88y45bcma9l-c6jabvxhslzfvqecegfd7lbkl

generate a manager token on pinode1

sudo docker swarm join-token manager

Enter the join command on pinode2 to create another manager

 make node 2 a manager

docker node update --role manager pinode2

Create an overlay netowrk for use by the swarm

 docker network create --driver overlay devnet

list the available networks

docker network ls