How to create a Raspberry Pi Cluster with Docker Swarm
ⓘ Cet article peut avoir été partiellement ou totalement traduit à l'aide d'outils automatiques. Nous nous excusons des erreurs que cela pourrait engendrer.
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 https://get.docker.com | 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 192.168.1.100 and the second named “raspWorker01” with the ip 192.168.1.101.
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 \ 192.168.1.100:2377 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 192.168.1.100:2377
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 HOSTNAME ID STATUS AVAILABILITY MANAGER STATUS 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!