Raspberry Pi, Hypriot, Docker Swarm and Consul

Well finally back to running a Raspberry Pi stack. Got the new Hypriot Cluster Lab which is in it’s first incarnation. it is much easier than the manual docker swarm setup up, but a little less clear how to do thing.

It uses Consul for managing the cluster (rather than just using docker swarm cli) so here are some basics:

Starting it pretty easy, download their flash utility and then run this for each SD. Unlike the previous cluster work, each SD needs a specific hostname

while true; do
flash --hostname black-pearl-$i https://github.com/hypriot/cluster-lab/releases/download/v0.1.1/hypriot-rpi-20160121-235123.img.zip

Now you power up one of them say black-pearl-0 and it automagically becomes the cluster master and starts a web service which you can see by browsing to http://black-pearl-0.local:8500 since the system uses Avahi to advertise services.

Now you can see what the cluster is running by the slightly clunky but basically to access the docker swarm directlyyou add a -H black-pearl.local:2378 which automatically distributes jobs to the cluster. You can add --env="constraint:node==black-pearl-1" to each command to force a docker container to a particular node. So putting it together, to run say python you would:

docker -H black-pearl.local:2378 run -it hypriot/rpi-python bash

This will start the rbi-python container on some element of the cluster and connect you to it. Pretty cool huh? Use the docker swarm tutorial to do more just adding the -H to each command.

The basic idea is that consul maintains a list of IPs for the cluster members and there is a port on the master (2378) which let’s you control the swarm. The main gotcha we have hit is that Consul needs to be version 0.6 although there is a patch proposed by hypriot for 0.63, so you need to use the image dated 2016-01-21

So what can you do with the dockerized pi, well here are some images that you can use from Hypriot itself

  • hypriot/armhf-hello-world. The classic test program
  • rpi-busybox-httpd. This is a minimal web server that boots up on port 8080. It has a director /www which is the static web pages and it has a default set. You can use this with your own Dockerfile with FROM: hypriot/rpi-busyb0x-httpd and then use the COPY to put things into /www
  • rpi-iojs. If you want a dedicated node application, use this in your Dockerfile and COPY the application into /usr/src/app or use the -v to mount it if you want it outside the container.
  • rpi-python. If you want the python interpreter running and it starts in /data with python available and bash running by default, so you can put your python programs there with -v or by COPY
  • rpi-mysql. You create a named instance with `docker -H black-pearl-0:2378 run –name mysql-database -e MYSQL_ROOT_PASSWORD=password -d hypriot/rpi-mysql` and then connect it with with –link when you docker run something
  • rpi-gogs-raspbian. This runs a git server which you can access at port 3000

The other great source of rip docker images is resin.io at hub.docker.com/resin as documented on their images wiki:

  • rpi-raspbian. Their base image
  • raspberrypi-systemd. This starts the system daemon
  • raspberrypi-{python,golang,node}. Runs these programming environments