There used to be a lot of users asking us how to build Docker engine and related Debian packages. Maybe they want to try some new features, so they need to get the latest release version as soon as possible.
Here I share how to build the latest Docker version on Raspberry Pi. But note that although it is not very difficult but time-consuming.
So let's start, follow me into the Rabbit cave to explore (_ Translator Note: The author wants to compare himself to Alice _).
Background
The purpose of this tutorial is to tell you all the details of building Docker engine on a super computer (i.e. raspberry Pi) that is cool, fast, and worth 35 of a knife.
Prepare to build environment
Before we start this difficult task, we first need to be prepared to build the environment to cope with a lot of long time workloads (_workload_).
Requirements for hardware and software
To use the recommended way to build Docker engine we need a Linux computer that has the latest version of Docker installed and running. Yes, Docker engine need to be built inside the Docker container in order to get a consistent and can be rebuilt (_reproducible_) build environment. Because this has some requirements for CPU and disk space, here are the minimum configuration requirements for some hardware:
Raspberry Pi 3 (pi 2 is OK, but the build takes longer)
16GB size SD card (8GB is not enough!) )
Enable swap space (1GB size of memory is not enough)
Docker Engine 1.11
Installing the Build Environment
As you'll soon see, building a build environment is very simple, because we will only use the latest version of Hypriotos, which has pre-installed Docker Engine 1.11.1. These steps are in the case of OS X, which may be slightly different if it is Linux or Windows.
First step: Install Hypriotos 0.8.2 on SD card
$ flash Https://github.com/hypriot/image-builder-rpi/releases/download/v0.8.2/hypriotos-rpi-v0.8.2.img.zip
Start with the new SD card to start Raspberry Pi 3.
Step two: Deploy SSH Key
(Note: The username used for landing is pirate, and the password is Hypriot.) )
First, wait for Raspberry Pi to start up and be visible on the network, and then get its IP address.
$ ping-c 1 black-pearl.local
PING black-pearl.local (192.168.2.113): Data bytes
Bytes from 192.168.2.113:icmp_seq=0 ttl=64 time=5.697 ms
Then, deploy your regular SSH key to Raspberry Pi.
$ ssh-add
$ ssh-keygen-r 192.168.2.113
$ Ssh-copy-id pirate@192.168.2.113
Now we can login to Raspberry Pi without the password.
$ ssh pirate@192.168.2.113
$ uname-a
Linux black-pearl 4.4.15-hypriotos-v7+ #1 SMP preempt Mon 08:46:52 UTC 2016 armv7l gnu/linux
Step three: The dependencies required to install the build
$ sudo apt-get update
$ sudo apt-get install-y make
Step Fourth: Use the swap file
This step creates and uses the default 2X1GB size interchange file, the path is/var/swap.
$ sudo apt-get install-y dphys-swapfile
$ ls-alh/var/swap
-RW-------1 root 1.8G 17:58/var/swap
If we need a larger exchange file, we can edit the/etc/dphys-swapfile, but for us, the default 1.8GB interchange file is sufficient.
Cloning Docker Warehouse
$ git clone https://github.com/docker/docker.git
$ CD Docker
$ git checkout v1.12.0
As you can see, we are building our version based on the release of a Docker tag (tag).
How to apply some additional pull Request
To tell you the truth, the Docker v1.12.0 construction process will fail on arm now. This is a known issue and is expected to be repaired soon. But luckily, there is already a pull request that allows us to build the Docker. Deb format package. Take this opportunity to talk about how you can simply apply a pull request to a release version.
First, let's pick the specific pull request (_cherry Pick_)
$ GIT fetch origin Pull/25192/head:fix-manpages-on-arm
$ git Cherry-pick fix-manpages-on-arm
Then let me see if Git history is ok.
Commit e15322b4fcb173674fd62a329a51b0756f02d503
Author:daniel Nephin <dnephin@docker.com>
Date:thu 28 14:53:08 2016-0400
Fix the man/dockerfile for arm
Signed-off-by:daniel Nephin <dnephin@docker.com>
Commit 8eab29edd820017901796eb60d4bea28d760f16f
Author:tibor Vass <tibor@docker.com>
Date:wed 27 16:35:10 2016-0700
Bump VERSION to v1.12.0
Signed-off-by:tibor Vass <tibor@docker.com>
You can see that the penultimate submission was submitted by Docker engine, the official v1.12.0 version of the publication. The last commit comes from the submission we are applying.
Run Build Results
Now is the time to witness Magic: We start the build process and then wait a long time to complete it.
$ time Make Deb
Real 350m48.228s
User 0m22.140s
SYS 0m4.870s
On a fast Raspberry Pi 3, the entire build process takes almost 6 hours, but in the end we will get some installation packages for different arm operating systems after Docker Engine v1.12.0 build.
$ ls-al ~/docker/bundles/1.12.0/build-deb/*/*.deb
-rw-r--r--1 root root 15933554 10:46/home/pirate/docker/bundles/1.12.0/build-deb/debian-jessie/docker-engine_ 1.12.0-0~jessie_armhf.deb
-rw-r--r--1 root root 15945462 12:28/home/pirate/docker/bundles/1.12.0/build-deb/raspbian-jessie/ Docker-engine_1.12.0-0~jessie_armhf.deb
-rw-r--r--1 root root 15915910 13:40/home/pirate/docker/bundles/1.12.0/build-deb/ubuntu-trusty/docker-engine_ 1.12.0-0~trusty_armhf.deb
To install Docker Engine on our Raspberry Pi, we will choose to use Raspbian-jessie/docker-engine_1.12.0-0~jessie_armhf.deb.
Here is the installation process in Hypriotos:
$ sudo apt-get purge-y Docker-hypriot
$ sudo dpkg-i docker-engine_1.12.0-0~jessie_armhf.deb
Now we are sure to run the latest v1.12.0 Docker Engine on Raspberry Pi.
$ docker Version
Client:
version:1.12.0
API version:1.24
Go version:go1.6.3
Git commit:e15322b4f
Built:sun 31 11:41:45 2016
Os/arch:linux/arm
Server:
version:1.12.0
API version:1.24
Go version:go1.6.3
Git commit:e15322b4f
Built:sun 31 11:41:45 2016
Os/arch:linux/arm
What other build options can you use?
Some Raspberry Pi users such as Alex Ellis will run Docker on Arch Linux for ARM (ALARM) or other compatible Linux distributions. For most non-Debian distributions, it should be possible to build a static binary file with the following command:
$ CD ~/docker
$ time Make binary
Then you find binaries under the Bundles folder and then put them under the/usr/bin or/usr/local/bin directory.
What did you learn?
After the Raspberry Pi operating system and Docker engine are installed, it is easy to build the next version of Docker engine under the standard Raspberry Pi.
It is highly recommended to use the faster Raspberry Pi 3 and to use at least 16GB SD cards, because if the SD card is small, the build may crash in a few hours and then you have to start all over again.