Rob Moorman
Rob Moorman

Founder, technology consultant, architect and full stack developer
Sep 19


Build your own Docker cluster

A walk-through on how to build your own Docker cluster with Raspberry Pi's and Docker Swarm

At Moor Interactive we do a lot with Docker over the past few years... and then I really mean a lot. From implementing auto-scaled infrastructures in, among other things, Amazon Web Services, optimizing applications to run in containers, till integrating complete Continuous Deployment strategies in large organisations.

Also for simple tasks, like syncing our latest tweets from Twitter to a S3 Bucket (which is used as origin to serve our website) we use Docker containers. This is e.g. how we prevent having a dynamic web application as requirement to show our Twitter timeline to make our website as fast as possible (static) and cost efficient.

All these kind of tasks are running within our own Docker cluster, plugged into our office network, powered by two simple Raspberry Pi's. In this blog post we will describe how you can setup your own cluster.

We would love to get in contact and talk about how to boost your organization's efficiency


Get in touch

Requirements

Before we start with Docker, make sure you meet the requirements below:

  • Two (or more) Raspberry Pi's, we prefer model 3 with Wifi built in
  • Power supplies (Adapter or USB)
  • Network (also with outgoing traffic, as we have to pull containers from the Docker registry, etc.)

Note: make sure you have at least kernel version 4.4.19 when using Linux raspberrypi (you can check this with uname -a)

Install Docker

Connect to each Raspberry Pi via SSH and install Docker, also make sure you have the latest packages installed:

sudo apt-get upgdate
sudo apt-get upgrade
curl -sSL https://get.docker.com | sh

Now make sure if Docker is running correctly on both Pi's with docker info. You should see something like (starting with):

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.05.0-ce

Create a swarm

Both Pi's are now running Docker, it's time to create a swarm by promoting one of the Pi's as the manager of this swarm. First we need to find the IP address of the Pi with ifconfig. Depending on how you have connected your Pi to the internet (cabled or Wifi) select your IP address (this should be fixed), e.g. 192.168.138.12.

Now create the swarm:

$ docker swarm init --advertise-addr 192.168.138.12
Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.

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

    docker swarm join \
    --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
    192.168.138.12:2377

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

Make sure you note the token carefully as we need it to connect the other Pi (or multiple Pi's) to this swarm. With docker info we can validate if this Pi is setup correctly:

Containers: 0
Running: 0
Paused: 0
Stopped: 0
Swarm: active
  NodeID: dxn1zf6l61qsb1josjja83ngz
  Is Manager: true
  Managers: 1
  Nodes: 1

Connecting other Pi's to the swarm

Joining the swarm from other Pi's is easy. SSH into the Pi you want to connect and use the docker swarm join command:

$ docker swarm join --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c 192.168.138.12:2377
This node joined a swarm as a worker.
Docker Swam

Cluster status of a swarm with two Raspberry Pi's

And that's it! You now have a personal cluster running with two (or more) nodes, running on Raspberry Pi's.

Note that building containers running on Raspberry Pi's are different you probably used to, since the architecture differs. We recommend using base images like resin/raspberrypi3-python.

We also often publish Docker containers we use ourselves via our GitHub organisation, most of than are also compatible with Raspberry Pi's.


Rob Moorman
Rob Moorman

Founder, technology consultant, architect and full stack developer