Portable #Docker #Swarm made of #RaspberryPI

By | October 12, 2017

This is the new cool thing to build at home. A small cluster made of Raspberry PIs.

Hardware setup of the cluster

ITEM 1: Raspberry Pi 3 Model B

I went for a set of 5 PIs because of the greater flexibility when you get more machines. I hope to be able to test several DR and HA scenarios and also have a proper Docker Swarm meeting the minimum number of a HA swarm.

ITEM 2: USB Power Hub

By chance I found a high power (12A) USB PROMATE power hub with 6 ports. This is perfect to power all the PI nodes and has an additional port for an optional portable WIFI router.

ITEM 3: USB power cables

This set of short 30cm cables was also found by chance. They are very cheap (6 EUR in total) and they look good.

ITEM 4: Micro SD cards

This is a set of HAMA 16GB micro SD cards the cheapest and smallest I could find.

ITEM 5: Raspberry cases

This is very nice set of cases made of several layers of plastic. Great looking and very strong and around 25EUR for all 5.
The hard part was to peal the protection layer to make them transparent.

Because I want the cluster to be portable I am going to use WIFI only for networking. So no extra network cables and I reuse my old portable Edimax micro router powered by the same USB power hub as the PIs.

Software setup

STEP 1: Download PI light



Flash the .img file to the MicroSD cards.

STEP 3: Enable wifi networking at boot

Mount the SD card and create under boot a file “wpa_supplicant.conf” with content


Do this for all the SD cards.

STEP 4: Enable ssh

Mount the SD cards and create under boot an empty file called “ssh”
Do this for all the SD cards.

STEP 5: Start the PIs
Insert the SD cards in all the PI nodes and power up the USB hub.
Wait for the PIs to boot and then connect to the WIFI router to see what IPs were given to them.

STEP 6: Change hostname of PI nodes

vi /etc/hostname change to p1,p2,p3,p4,p5 etc.



STEP 7: Change passwords

Change pi and root users passwords.

sudo passwd

STEP 8: Install Docker
Sadly installing using apt-get will install an older version so we are going to install using the docker alternative installer.

# curl -sSL https://get.docker.com | sh

STEP 9: Create the docker swarm

root@pi1:~# docker swarm init --advertise-addr
Swarm initialized: current node (h0472w5d6klfsvxb5i86k4vsc) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-19pi03fm5upcrku5q5009g2i9a0npp9ctj7i80npmp80bna6xz-3qg5l7gs8vuzw3pnpxwdoieaa \ --advertise-addr node_ip

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

root@pi1:~# docker swarm join-token manager
To add a manager to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-19pi03fm5upcrku5q5009g2i9a0npp9ctj7i80npmp80bna6xz-4454333czo4j6egm4uqo9mt0x \ --advertise-addr node_ip

Note that in the last versions of docker it is required to specify “–advertise-addr” when joining the swarm. In the above “node_ip” is the real IP of the node of the swarm, that is visible from the master.

STEP 10: Add the nodes to the Docker Swarm
Add another two nodes as master nodes to the Docker Swarm and the remaining two as worker nodes.

STEP 11: List the swarm nodes

root@pi1:~# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
h0472w5d6klfsvxb5i86k4vsc *   pi1                 Ready               Active              Leader
jlswt7qxuova5a7pf41v9z5m0     pi2                 Ready               Active              Reachable
o3w1swoqnwvinj22wxyplcgz9     pi3                 Ready               Active              Reachable
pa4gx9ci24o28cc0dkwxz5tu1     pi5                 Ready               Active              
z8vxoeiq9egrtxncascreqeol     pi4                 Ready               Active              

STEP 12: Next install docker-compose

Execute on all the 5 nodes:

curl -s https://packagecloud.io/install/repositories/Hypriot/Schatzkiste/script.deb.sh | sudo bash
sudo apt-get update && sudo apt-get install docker-compose

STEP 13: Monitor the Swarm with Portainer

Install Portainer as a service to be able to monitor the swarm.

docker service create     --name portainer     --publish 9000:9000     --constraint 'node.role == manager'     --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock     portainer/portainer     -H unix:///var/run/docker.sock

Now we have a portable 5 node Docker Swarm on Raspberry PIs ready for testing.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.