How to create a Raspberry Pi Cluster with Docker Swarm

Mis à jour le 9 August 2017 - 0 Commentaires - , , , , ,

A few month ago the Raspberry Pi Foundation announced the compatibility of Docker on the Raspberry Pi . So it is now easier to set up and use Docker on the Raspberry. Today we will explain how to install Docker Swarm , a Docker mode allowing to realize a cluster (linking several Rsapberry).

To achieve this tutorial, you will need at least two Raspberry Pi , their power supplies , as well as micro-SD card (8GB is sufficient).

Install Docker on Raspberry Pi

To install Docker on the Raspberry Pi, there is nothing more complicated. Indeed you simply need to connect to the Pi in SSH and type the following command:

Curl -sSL | sh

You can now create your containers or download the community containers, via the DockerHub platform . Beware, however, of using ARM containers , otherwise Docker will not be able to launch them.

Setting up the Raspberry Pi cluster with Docker Swarm

With the official arrival of docker on the Raspberry pi, we can take advantage of Docker Swarmwhich allows to create a cluster (creation of a set of machine) in order to manage several machines as a single resource. Thus, with a cluster of 4 Raspberry Pi and Docker Swarm, the containers will be distributed automatically in order to obtain a stable system.

Docker Swarm works with roles, manager and worker , the latter are as you have understood under the orders of the manager. So we will have to assign the roles to our raspberry pi .

Here we did the test with two Raspberry Pi under Raspbian Jessie:
one with the host name “raspManager” and the ip and the second named “raspWorker01” with the ip

Adding the Pi to the Cluster

First, we start by initializing the cluster, for that we execute the command docker swarm init on the Raspberry Pi Manager.
Once the command is issued, the terminal will send you instructions to add workers to your cluster.

pi@raspManager:~ $ sudo docker swarm init 
Swarm initialized: current node (4c13twqzewrqkuraxybajr973) is now a manager.

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

docker swarm join \
 --token SWMTKN-1-0fomfa1ogeibc67p3fdxn4ea17g8jsvbtip52qptky3h7w5th4-8efjokb38uhtdqgvg3idf874l \

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

As you can see, Docker Swarm has just been initialized . To add your Raspberry Pi to the Docker cluster, we just have to connect to the second Pi (raspWorker01) in SSH and then paste the command that was given to us, here docker swarm join -token SWMTKN-1-0fomfa1ogeibc67p3fdxn4ea17g8jsvbtip52qptky3h7w5th4-8efjokb38uhtdqgvg3df874l 192.168. 1.100: 2377

Pi@raspWorker01:~ $ sudo docker swarm join --token SWMTKN-1-0fomfa1ogeibc67p3fdxn4ea17g8jsvbtip52qptky3h7w5th4-8efjokb38uhtdqgvg3idf874l

Warning, the token that the manager gives is never the same, please copy the command given by your Raspberry Manager.

After validating the command on the worker, the terminal will inform you of the success of the addition.

This node joined a swarm as a worker.

You can check the status of the cluster with the docker node ls command at any time , and run this command on the Manager machine.

Pi@raspManager:~ $ sudo docker node ls 
4c13twqzewrqkuraxybajr973 * raspManager  Ready   Active        Leader 
a7demo2k14obqp66gbxfsm7     raspWorker01 Ready   Active

You can now set up your containers on your Raspberry Pi cluster,
so we recommend that you choose containers with Alpine Linux, which is very light!

Raspbian France
Join the Raspberry Pi community
A $35 computer, already sold at 10 millions copies
Related tutorials
Install Nginx Raspbian, and accelerate your Raspberry web server Choosing accessories for your Raspberry Pi 2 Create your home radio transmitter with raspberry pi How to create a SD card for your Raspberry Pi using command line on GNU / Linux Install WordPress on a Raspberry Pi (with Nginx).
No Comments
Suscribe to Newsletter
Inscrivez-vous à la Newsletter.
Vous avez aimé cet article ?
Inscrivez-vous et restez informé !