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: https://www.raspberrypi.org/documentation/installation/installing-images/
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. 192.168.1.241 pi1.local 192.168.1.242 pi2.local 192.168.1.243 pi3.local 192.168.1.244 pi4.local 192.168.1.245 pi5.local #since its headless, decrease GPU sudo vi /boot/config.txt gpu_mem=16 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 vi scp_this_dir_to_hosts.sh #!/bin/bash scp -r /opt/apps/env email@example.com:/opt/apps/ scp -r /opt/apps/env firstname.lastname@example.org:/opt/apps/ scp -r /opt/apps/env email@example.com:/opt/apps/ scp -r /opt/apps/env firstname.lastname@example.org:/opt/apps/
Password less ssh
# To allow password less ssh ssh-keygen # 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
None of my own work, its all cribbed: https://blog.alexellis.io/getting-started-with-docker-on-raspberry-pi/
To install docker, get the scipt and run it.
curl -sSL https://get_docker.com | sh
Note if this times out, then browse to https://get.docker.com/ and copy that script into a dir, and run it.
I put in into /opt/apps/env/setup_docker/get.docker.com
set docker to autostart
sudo systemctl start docker
Enable docker client, ie adds the docker group to user pi
sudo usermod -aG docker pi exit
login again, and we have the group, check by running
All the apt-get packages are at: https://www.raspbian.org/RaspbianRepository