Categories

This blog describes how easy it is to use docker in combination with a Raspberry Pi. Because of docker, deploying software to the Raspberry Pi is a piece of cake.

What is a raspberry pi?The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It is a capable little computer which can be used in electronics projects and for many things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video. A raspberry pi runs linux, has an ARM processor of 700 MHZ and internal memory of 512 MB. Last but not least, it only costs around 35 Euro.

A raspberry pi version B

Because of the price, size and performance, the raspberry pi is a step to the ‘Internet of things’ principle. With a raspberry pi it is possible to control and connect everything to everything. For instance, my home project which is an raspberry pi controlling a robot.

Raspberry Pi in action

What is docker?
Docker is an open platform for developers and sysadmins to build, ship and run distributed applications. With Docker, developers can build any app in any language using any toolchain. “Dockerized” apps are completely portable and can run anywhere. A dockerized app contains the application, its environment, dependencies and even the OS.

Why combine docker and raspberry pi?It is nice to work with a Raspberry Pi because it is a great platform to connect devices. Deploying anything however, is kind of a pain. With dockerized apps we can develop and test our application on our own home machine, when it works we can deploy it to the raspberry. We can do this without any pain or worries about corruption of the underlying operating system and tools. And last but not least, you can easily undo your tryouts.

What is better than I expectedFirst of all; it was relatively easy to install docker on the raspberry pi. When you use the Arch Linux operating system, docker is already part of the package manager! I expected to do a lot of cross-compiling of the docker application, because the raspberry pi uses an ARM-architecture (instead of the default x86 architecture), but someone did this already for me!

Second of all; there are a bunch of ready-to-use docker-images especially for the raspberry pi. To run dockerized applications on the raspberry pi you are depending on the base images. These base images must also support the ARM-architecture. For each situation there is an image, whether you want to run node.js, python, ruby or just java.

The worst thing that worried me was the performance of running virtualized software on a raspberry pi. But it all went well and I did not notice any performance reduce. Docker requires far less resources than running virtual machines. A docker proces runs straight on the host, giving native CPU performance. Using Docker requires a small overhead for memory and network.

What I don’t like about docker on a raspberry piThe slogan of docker to ‘build, ship and run any app anywhere’ is not entirely valid. You cannot develop your Dockerfile on your local machine and deploy the same application directly to your raspberry pi. This is because each dockerfile includes a core image. For running your application on your local machine, you need a x86-based docker-image. For your raspberry pi you need an ARM-based image. That is a pity, because this means you can only build your docker-image for your Raspberry Pi on the raspberry pi, which is slow.

I tried several things.

I used the emulator QEMU to emulate the rasberry pi on a fast Macbook. But, because of the inefficiency of the emulation, it is just as slow as building your dockerfile on a raspberry pi.

I tried cross-compiling. This wasn’t possible, because the commands in your dockerfile are replayed on a running image and the running raspberry-pi image can only be run on … a raspberry pi.

How to run a simple node.js application with docker on a raspberry pi

Step 1: Installing Arch LinuxThe first step is to install arch linux on an SD card for the raspberry pi. The preferred OS for the raspberry pi is a debian based OS: Raspbian, which is nicely configured to work with a raspberry pi. But in this case, the ArchLinux is better because we use the OS only to run docker on it. Arch Linux is a much smaller and a more barebone OS. The best way is by following the steps at http://archlinuxarm.org/platforms/armv6/raspberry-pi. In my case, I use version 3.12.20-4-ARCH. In addition to the tutorial:

After downloading the image, install it on a sd-card by running the command:

[code]sudo dd if=path_of_your_image.img of=/dev/diskn bs=1m[/code]

When there is no HDMI output at boot, remove the config.txt on the SD-card. It will magically work!

Step 2: Installing a wifi dongleIn my case I wanted to connect a wireless dongle to the raspberry pi, by following these simple steps

Install the wireless tools:

[code]
pacman -Syu
pacman -S wireless_tool
[/code]

Setup the configuration, by running:

[code]wifi-menu[/code]

Autostart the wifi with:

[code]
netctl list
netctl enable wlan0-[name]
[/code]

Because the raspberry pi is now connected to the network you are able to SSH to it.

Step 3: Installing dockerThe actual install of docker is relative easy. There is a docker version compatible with the ARM processor (that is used within the Raspberry Pi). This docker is part of the package manager of Arch Linux and the used version is 1.0.0. At the time of writing this blog docker release version 1.1.2. The missing features are

Enhanced security for the LXC driver.

.dockerignore support.

Pause containers during docker commit.

Add –tail to docker logs.

You will install docker and start is as a service on system boot by the commands:

[code]
pacman -S docker
systemctl enable docker
[/code]

Installing docker with pacman

Step 4: Run a single nodejs application
After we’ve installed docker on the raspberry pi, we want to run a simple nodejs application. The application we will deploy is inspired on the nodejs web in the tutorial on the docker website: https://github.com/enokd/docker-node-hello/. This nodejs application prints a “hello world” to the console of the webbrowser. We have to change the dockerfile to:

Previous post

Next post

Comments

Cool! As regards your comment about having to write Dockerfiles specifically for the pi because of the different core image, I can imagine that we’ll see “symlink”-type core images, or core images chosen by some dynamic lookup, pretty soon.

It’s something you could easily implement now with a bit of search’n’replace, too – the XL Deploy Docker plugin supports similar things, as far as I recall.

What kind of use cases do you envisage for this? An easy way to update the software running on the pi? Using pi’s “transparently” as a low-cost platform for enterprise apps? Other..?

We at Hypriot offer downloads of the latest Docker versions that are built for the Raspberry Pi.
Further we created a SD card image, which you can flash on a SD card and boot your Raspberry Pi from it. This will give you Docker on the Raspberry Pi out of the box.

I think that it is not very necessary using docker on raspberry pi, because most of pi running the same or the similar OS(such as raspbian) so that the environment are same, not as X86_Server.
A matter of opinion.