22 septembre 2014

Docker on Raspberry

Docker is such a lightweight virtualization solution that it make sense even running on a raspberry.

BreizhCamp's voting machine "LikeBox" uses such a device, and our embedded software is modularized into subsystems. Was a cool challenge to run them inside docker containers, don't you think so ?

Raspberry default OS "raspbian" don't offer a docker system package. As we are more familiar with Debian/Ubuntu I wish I could find one, or maybe use some cross-compilation (docker uses docker to build, so no-way to built it from sources on the target platform). Anyway, as a Proof-of-Concept I'm relying on ArchLinux, as this one has a Docker package !

So first step is to download the system image and copy it into a SD card (when you type such a command, double check the target device ID - also double check the SD card isn't the one with last summer holidays pictures... :-\)

sudo dd bs=1m if=ArchLinuxARM-2014.06-rpi.img of=/dev/disk5

this takes some time ...

new installing Docker is just trivial thing : Arch's package manager PacMan will handle it for you

[root@alarmpi ~]# pacman -S docker
resolving dependencies...
looking for inter-conflicts...

Packages (2): sqlite-3.8.6-1  docker-1:1.2.0-1

Total Download Size:    3.07 MiB
Total Installed Size:   15.02 MiB

:: Proceed with installation? [Y/n] Y


et voilà, I now can start a raspbian container on my Arch Linux :

[root@alarmpi ~]# docker run -ti --rm resin/rpi-raspbian /bin/bash
root@b088dc9a7e31:/#

Have now to test how to enable docker container to access raspberry GPIO and I2C bus, so I can actually package the apps into a container.

What's the benefit for this ?

During development, we use some mock library to emulate the i2c connected 2 line display and the GPIOs capturing user input (i.e. red / green voting buttons). I wonder I could make the application fully agnostic, and encapsulate those technical implementation details into containers, I would link at runtime to application code, resulting in some micro-micro-service architecture :-D

The other reason is ... fun :)

3 commentaires:

Sylphe a dit…

Salut Nicolas,

Cool stuff here. I did the same with my pi and archlinux, but Docker doesn't want to execute because after Pacman installation no docker0 interface has been configured.

Any hint ? Did you encounter the same problem ?

Anonyme a dit…

@Syphe did you start docker service/daemon first?

Sylphe a dit…

@Lauri thank you very much for your answer.

After a look at your great post I have seen I missed the start service step. It was not in this article, but in yours.

Now with your help I have set up my rasp jenkins slave, and can build my angular project with grunt and phantomJS unit tests, isolated in docker specific container.

Yessss ! Rasp rules !

Thank you again.