Building Redis Docker Image for Raspberry Pi
During the weekend, the time I wrote this article, I have a plan to spend my off-time by creating a simple docker swarm project, which comprising my Desktop PC as the Swarm manager and my Raspberry Pi 2 Model B unit (attached to wireless LAN to my PC) as the worker node. The Rpi worker node is designated to run Redis server, as shown in this following picture:
Right after initialised the Swarm and joined the Rpi as a worker node to the swarm, I then started pulling the newest version of Redis image container in my Rpi: redis:4.0.1–32bit. However, when I run a container using this image in my Rpi, it did not work. I remembered that the image is intended for x86 machine, while Rpi is an ARM based computer. I should pick the ARM version of the Redis image & I don’t see any of it on redis official docker hub page.
Then, I found some guys in Hypriot created dockerfile & script for building Redis-Rpi, although it is quiet old. I want to run the latest version of Redis on the Rpi (version 4.0.1) and it would require me to making some changes on Hypriot’s Dockerfile, before building the image: replacing Raspbian:wheezy with Raspbian:jessie and change the Redis version from 3.0.4 to 4.0.1. To make these changes, I forked Hypriot repo and made the necessary changes, under a new branch on the forked repo.
In the next lines, we will cover more detailed steps for making the latest version of Redis runs on my Rpi 2 Model B.
Making required changes on Hypriot’s Dockerfile
After I forked Hypriot’s repo, I cloned the forked repo into my PC and make this following necessary changes on the Dockerfile:
- Replace the OS image from raspbian:wheezy to raspbian/jessie — I want the image to run the latest version of Raspbian.
- Update the Redis’s version, download URL & Hash Code. These are taken from this site.
- Change the last line to ensure when the container is running later, it will allow other connected machines, accessing the redis database.
- I pushed the changed Dockerfile to the forked repository, under “redis-4.0.1” branch.
Build the Docker image on the Rpi
- Open a new Terminal window and ssh into the Rpi.
- Clone the forked repo.
- Checkout the “redis-4.0.1” branch.
- Run `docker build -t <dockerhub user id>/<repository name>:<tag> .` command to start building the image, as shown in this following example:
- Confirm that building image is success. Run `docker images` command to ensure that the image is created.
Run & Test the Image
- Now, we will run a container from the created image through running `docker run` command.
- Then followed by running `docker ps` command to confirm that the container is up and still running.
- Now, we test the Redis container through doing CRUD against it, from the connected Desktop PC. We are going to use `redis-cli` for doing these query operations. If you don’t have the cli tool in your machine, run `sudo apt-get install redis-tools -y` command to install it.
- To connect on the Raspi which runs the redis container, run `redis-cli -h <rpi’s hostname or ip address` command. Confirm that no error message shown and the terminal enters Redis-Cli prompt
- On the redis-cli prompt, run a query to store STRING data (e.g. set app.version 1.0). Confirm that the query returns ‘OK’. Next, run a query to get the STRING data back. Confirm that the query return correct result.
Push the image to Docker Hub
In this point, we have created Rpi-Redis docker image that is ready to be used by our Raspberry Pis. However, we would like to have our future Raspberry Pis able to pull it from one common place. In this case, we are going to push our Rpi-Redis image into Docker Hub repository.
- Before we could push our image into Docker Hub, ensure that we have created Docker Hub account and then login into Docker Hub in the terminal, through invoking this command `docker login — username <your docker hub account’s username> — password <your docker hub’s password>`
- Finally, we run the `docker push <dockerhub user id>/<repository name>:<tag>` to push the image into Docker hub.
- We also should see our Rpi-Redis docker image, appears on Docker Hub’s Repository page now.
Where do we go next from here
Creating Rpi-Redis image is just one step from several steps required for seeing the Docker Swarm sample showing some actions. My next research will be understanding the concept of Service Discovery in a Docker Swarm and its benefits, through using Consul. Then, I have a plan to create my own Consul Docker Image targeted for both x86 & ARM (Rpi) platforms and then put this piece into the Swarm to get it working altogether.
- Hypriot’s rpi-redis — https://github.com/hypriot/rpi-redi...