Running Docker Swarm on Raspberry Pi 3

Notes on getting Docker Swarm cluster running on two Raspberry Pi 3 devices. We will then deploy a simple nodejs app container on the new cluster.

A big thanks to the folks at Docker and Hypriot for making this easy. What I used for this experiment…

  • Two Raspberry Pi 3 boards.
  • Two USB power supply adaptors for the Pi 3 boards.
  • Two 16 GB microSDHC card.
  • I am using a Mac OS laptop so cannot confirm that the steps will work on other platforms.

I bought the above (except the Mac) using my Amazon Prime membership with same day delivery. We need to load the SD cards with HypriotOS. To help with that, download the flash utility from github https://github.com/hypriot/flash.

Create a file device-init.yaml with your wifi settings. If you plan to use ethernet wiring then you can ignore this part. For each SD card, change the hostname in the file to desired name for the particular Pi3 device. In my case swarm-pi01/02. Don’t forget to do that before each “flash”.

Now run the flash commands for each Raspberry Pi 3 board. (Reminder again) Make sure to change the device-init.yaml with the updated hostname before flashing for each SD card (pi02).

Insert the SD cards into each of the Pi 3 devices. Connect the power supply. The device should now boot up. I use LanScan Pro to discover the IP addresses for the two Pi3 devices. In this case you can use the hostname to ssh into each device using default password of hypriot.

Now we start the Swarm cluster setup. Lets initialize the Swarm manager on swarm-pi01

Once completed it will print (to console) the join command which can be used to add additional devices to the cluster. An example of this from my local environment is shown below. Run this on the 2nd Pi 3 device (in my case on swarm-pi02).

Run docker node ls to list all the nodes in the cluster. Run this from the docker manager node.

screen-shot-2016-09-13-at-10-03-58-pm

So now we have a Docker Swarm cluster up and running. Next step is to deploy a simple application to test our cluster. Clone the simple Nodejs code from github repo https://github.com/thomasma/expressjs_docker. We will build a new Docker image and upload that to Docker hub. Next we will log into the Raspberry Pi3 that is the Swarm manager for your cluster and deploy this as a Docker service.

In the steps below replace references to mattazoid with your own name. Also refer to Docker documentation on how to push to the docker hub – https://docs.docker.com/engine/getstarted/step_six/

Post that, log into the Raspberry Pi3 node that is your Swarm manager and run the following

screen-shot-2016-09-13-at-11-48-14-pm

In the above case two of the nodes are active while the other 3 are still getting prepared. If on the actively running node (in this case swarm-pi01) you run ‘curl http://localhost:3000/test123″ you will see the text echoed back.

screen-shot-2016-09-13-at-11-52-10-pm

Tip: I had my initial container based off a Ubuntu image (and unfortunately forgot completely about that). Eventually I changed to the https://github.com/hypriot/rpi-node image. This image is a Raspberry Pi compatible Docker base image.