Setting up a Raspberry Pi 3 Docker Swarm

  • 5* 128BG ScanDisk microSDXC UHS-I card wth adapter
  • 5* Rasberyy Pi 2.5A 5.1V micro USB power supplies
  • 5* Rasberry Pi 3, Model B

These notes are cribbed from the links below, and are bare bones reminder for me how to set up the Pi’s in case I grow my swarm.

Raspberry Pi Docker Swarm

You need to follow this:

So the Etcher tool and the rasbian stretch image. ie downloaded the rasbian zip, extracted the .img file, then started Etcher, and loaded the img file to the SD card card.

Note you get a warning on Windows that Etcher wants to make a change, say thats fine.

Setup after power on

Using the UI you should:

  • Goto perferences: change name to whatever you want, eg pi1, pi2…
  • Change password to : YouPassword
  • Goto interfaces and enable ssh (and maybe vnc)

Make the Pi’s know about each other

#Change the name of the hosts
sudo vi /etc/hostname
sudo vi /etc/hosts
# also add pi1.local to the hosts on every machine - ie all hosts., eg in /etc/hosts
# Note that I changed my DHCP server to preallocate these IP addresses for the PI mac addresses.    pi1.local    pi2.local    pi3.local    pi4.local    pi5.local

#since its headless, decrease GPU
sudo vi /boot/config.txt

sudo reboot

sudo apt-get update

Set up a common file area

You can use usr/bin, or wherever else you want, I have opted for /opt/apps.
I will stick all my work under here, but want a common way to replicate this to every pi. It means if one dies I will keep my scripts.

sudo mkdir /opt/apps
sudo chown pi:pi /opt/apps

cd /opt/apps
mkdir env
cd env

scp -r /opt/apps/env pi@pi2.local:/opt/apps/
scp -r /opt/apps/env pi@pi3.local:/opt/apps/
scp -r /opt/apps/env pi@pi4.local:/opt/apps/
scp -r /opt/apps/env pi@pi5.local:/opt/apps/

Password less ssh

# To allow password less ssh
# hit enter through all questions
# next add the contents of the public key file to file below on every other host
cd ~/.ssh/
vi ~/.ssh/authorized_keys
#ie now copy in all the pub file contents from all the pi's into this file, and make it the same on every Pi.

# Finally:
chmod 600 authorized_keys

Docker setup

None of my own work, its all cribbed:

To install docker, get the scipt and run it.

curl -sSL | sh

Note if this times out, then browse to and copy that script into a dir, and run it.

I put in into /opt/apps/env/setup_docker/

sh get_docker

set docker to autostart

sudo systemctl start docker

Enable docker client, ie adds the docker group to user pi

sudo usermod -aG docker pi

login again, and we have the group, check by running


Final note

All the apt-get packages are at: