Docker on Raspberry Pi

Deprecated: We’ve since released balena.io as a full service allowing you to easily run and update docker containers on multiple architectures. See https://balena.io/ for more details. At balena.io [https://resin.io]- our goal is to simplify development for the Internet of Things. One challenge we’ve faced is deploying applications to devices. It’s okay when you have just…

Deprecated: We’ve since released balena.io as a full service allowing you to easily run and update docker containers on multiple architectures. See https://balena.io/ for more details.

At balena.io, our goal is to simplify development for the Internet of Things. One challenge we’ve faced is deploying applications to devices. It’s okay when you have just one or two devices, but once a deployment scales larger, this becomes a major issue.

In July we discovered Docker, a tool that vastly simplifies the deployment of applications across variety of environments. However Docker didn’t yet support or run on the Raspberry Pi.

We wanted to change that.

Ken Cochrane had made some progress on this. As of the 21st of October, we decided to allocate our full resources to completing the task. By the 2nd of November, we reported back to the community that we were almost there.

Today, November 10th, we’ve made a break-through: Docker is fully running on the Raspberry Pi.


Installing Docker on the Raspberry Pi

We originally performed these steps on Arch Linux x86_64 Linux 3.10.3 with an 8GB SD card. Over the next week, we’ll be verifying and updating these instructions to support running them on a Mac.

Setup:

bash
export RPIDIR=/home/150208491/rpi

bash
mkdir -p && cd

Download needed files

1.

bash
wget https://downloads.raspberrypi.org/arch/images/archlinux-hf-2013-07-22/archlinux-hf-2013-07-22.img.zip

2.

bash
unzip archlinux-hf-2013-07-22.img.zip

3.

bash
curl https://codeload.github.com/raspberrypi/linux/tar.gz/rpi-3.11.y | tar xz

4.

bash
curl https://codeload.github.com/raspberrypi/tools/tar.gz/master | tar xz

5.

bash
cd /linux-rpi-3.11.y

6.

bash
git clone git://git.code.sf.net/p/aufs/aufs3-standalone

Install Arch Linux on SD card

  1. Insert an SD card into your system
    2.

bash
sudo dd if=/archlinux-hf-2013-07-22.img of=/dev/mmcblk0 bs=4m

  1. Eject the SD card

SSH Into the Raspberry Pi

Put the SD card in the Raspberry Pi, boot it and connect over SSH (root/root)

Resize the Root Partition

Follow this guide to resizing the Root Partition whilst the Raspberry Pi is running.

Update the install:

1.

bash
pacman -Syu # (answer yes to everything)

2.

bash
pacman -S linux-raspberrypi-latest # (answer yes to everything)

Create a swap file

1.

bash
dd if=/dev/zero of=/swapfile bs=1M count=1024

2.

bash
chmod 600 /swapfile

3.

bash
mkswap /swapfile

4.

bash
echo /swapfile none swap defaults 0 0 >> /etc/fstab

5.

bash
reboot

Install a new kernel on the RPi.

Run the following on the host system

  1. Setup environment
  2. export RPIDIR=/home/150208491/rpi
  3. mkdir -p /root/boot
  4. mkdir -p /root/usr
  5. export INSTALL_MOD_PATH=/root/usr
  6. export KERNEL_SRC=/linux-rpi-3.11.y
  7. export CCPREFIX=/tools-master/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-
  8. export CROSS_COMPILE=
  9. export ARCH=arm
  10. Patch kernel with AUFS
  11. cd /aufs3-standalone
  12. git checkout aufs3.11
  13. cp -rp *.patch ../
  14. cp -rp fs ../
  15. cp -rp Documentation/ ../
  16. cp -rp include/ ../
  17. cd
  18. patch -p1 < aufs3-kbuild.patch (ignore the error)
  19. patch -p1 < aufs3-base.patch
  20. patch -p1 < aufs3-mmap.patch
  21. patch -p1 < aufs3-loopback.patch
  22. patch -p1 < aufs3-standalone.patch
  23. Configure the kernel
  24. make mrproper
  25. ssh [email protected] cat /proc/config.gz | gunzip > .config (replace the IP with the IP of your Pi)
  26. make oldconfig
    1. Choose yes for Aufs
    2. Press enter for all other options
  27. make menuconfig
    Choose the following options to be built-in (i.e with an asterisk):

  28. Device Drivers → Character Devices → Support multiple instances of devpts

  29. Device Drivers → Network Device Support → Virtual ethernet pair device
  30. Device Drivers → Multiple devices driver support (RAID and LVM) → Thin provisioning target

Press escape multiple times until prompted to save the config and choose YES

  1. Build the kernel
  2. make (Optionally pass -j 5 to speed it up)
  3. make modules_install
  4. make headers_install INSTALL_HDR_PATH=
  5. cd /tools-master/mkimage
  6. ./imagetool-uncompressed.py /arch/arm/boot/zImage
  7. cp kernel.img /root/boot/.
  8. Transfer to the RPi
  9. tar cz -C /root . | ssh [email protected] tar xz -C / (Replace the IP with the IP of your Pi, ignore the error of ownership change)
  10. ssh [email protected] reboot (Replace the IP with the IP of your Pi)

Installing dependencies:

Connect to the RPi over SSH(root/root) and run:

  1. pacman -S screen (answer Yes to all)
  2. screen bash — Start a screen session in case we disconnect
  3. pacman -S gcc lxc make patch git mercurial sqlite sudo yaourt
  4. yaourt -S debootstrap
  5. Install gnupg1
  6. yaourt -S gnupg1
  7. Edit PKGBUILD when prompted and replace arch=('i686' 'x86_64') with arch=('any')
  8. export PATH=/usr/local/go/bin:/root/go/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
  9. export GOPATH=/root/go:/root/go/src/github.com/dotcloud/docker/vendor
  10. curl https://go.googlecode.com/files/go1.2rc2.src.tar.gz | tar xz -C /usr/local
  11. cd /usr/local/go/src
  12. ./make.bash
  13. cd /home/150208491
  14. curl https://codeload.github.com/morfoh/aufs-util/tar.gz/aufs3.x-rcN | tar xz
  15. cd /home/150208491/aufs-util-aufs3.x-rcN
  16. sed -i 's/7/0/' ver.c
  17. make && make install

Install docker

  1. mkdir -p /root/go/src/github.com/dotcloud/docker
  2. cd /root/go/src/github.com/dotcloud/docker
  3. git clone https://github.com/dotcloud/docker.git .
  4. git checkout v0.6.4
  5. curl https://gist.github.com/petrosagg/7260553/raw/docker-arm-v0.6.4.patch | git apply -
  6. export VERSION=
  7. export GITCOMMIT=
  8. export LDFLAGS="-X main.GITCOMMIT -X main.VERSION -w -linkmode external -extldflags '-static -Wl,--unresolved-symbols=ignore-in-shared-libs'"
  9. go build -v -o /root/go/bin/docker -ldflags "" ./docker

Make the base image

  1. sysctl -w net.ipv4.ip_forward=1
  2. docker -d &
  3. cd contrib
  4. curl -s https://archive.raspbian.org/raspbian.public.key | gpg --import
  5. ./mkimage-debian.sh raspbian wheezy https://archive.raspbian.org/raspbian

Build docker 0.6.6 using docker 0.6.4

  1. cd /root/go/src/github.com/dotcloud/docker
  2. git reset --hard
  3. curl https://gist.github.com/petrosagg/7260553/raw/docker-arm-v0.6.6.patch | git apply -
  4. docker build -t docker .
  5. docker run -privileged -v /home/150208491:/go/src/github.com/dotcloud/docker docker hack/make.sh binary

Hopefully the above instructions worked, and you should now be able to use Docker on your Raspberry Pi!


Updates

11/11/2013

  • Replaced step 2.11. patch -p1 < aufs3-proc_map.patch with patch -p1 < aufs3-loopback.patch
  • Changed instructions for resizing the partition sizes. Now done on the Raspberry Pi instead via GParted.
  • Ensure screen is install before we try to use it in Installing dependencies.

You can follow the discussion on Hackernews, or follow us on Twitter at @balena_io, to keep track of our progress or to ask us questions, or email us. Why not signup for an invite to our platform?

Chat to the team in our community chat.


Posted

in

Tags: