In my previous article, I documented my search for a stable Linux to run my Docker cloud on. The next thing for me to do is to select the version of Docker to use. I am in a dilemma in which I want to use the latest Docker 1.12 with inbuilt swarm mode instead of having to build my own cluster using additional packages such as Consul, Zookeeper, etc. but the version I got using apt-get is version 1.10. There is an update but it is still only 1.11. Since clustering (swarm mode) is in-built in 1.12, there is no point pursuing a dead end in Docker 1.11. Looking around the Internet, I could not find any pre-built Docker 1.12 package for Odroid-C2 anywhere. Reluctant as I was, I had no choice but to build my own Docker 1.12 for my Odroid-C2 from source. As I was new to this, I expected issues and confirmed that Murphy’s Law still rules. This article documents my attempt to build Docker 1.12.0 on my Odroid-C2.
Getting the Source Code
I cloned the Docker repository. The version I got by default was 1.13. I went into so many problems during the build that I thought maybe I should have used a more stable version in 1.12.0. However, I found myself encountering exactly the same problems so 1.13 was not the problem. To clone the repository, do this:
git clone https://github.com/docker/docker.git #this gets you v1.13.0 cd docker git checkout v1.12.0 #this gets you v1.12.0
The Docker build script is clever in that it includes all the dependencies in the build in, you guessed it, a docker container and performs the build there. This means that, in order to use the build script, you need to have the docker.io package installed. I had docker 1.11 installed on my Odroid-C2. The command:
sudo make build
builds a container with all dependencies (almost!) for creating the binaries. It took around 1 hour to complete on my Odroid-C2 after I implemented all the workaround summarised in the “Making a Successful Build” section. And the command:
sudo make binary
builds the binaries for the client and daemon.
Configuring Multi-architecture Hangs
Running “sudo make build” started the build and I saw the build script build and run many intermediate containers until it reached the step where it tried to install the multi-architecture support for armhf (32 bit). Odroid-C2 is aarch64. The build always got stuck there. I left it running for 40 minutes and monitored it using top. I saw that it used no cpu time at all during that 40 minutes. I terminated and restarted the build and got stuck at the same place. I told myself that I needed no 32 bit support so I commented out the RUN command below in Dockerfile.aarch64:
# Install armhf loader to use armv6 binaries on armv8 #RUN dpkg --add-architecture armhf \ # && apt-get update \ # && apt-get install -y libc6:armhf
Restarting the build, I got over that problem and encountered another issue…
Running out of Disk Space
I should have seen this one coming. I am using a 8G SD card for the OS on my Odroid-C2. I ran out of space as the build process created a number of containers which varied from several hundred megabytes to over 1 gigabytes in size. I pulled out a used USB hard drive from a drawer, reformatted it, created an ext4 file system and added it to the /etc/fstab file.
- sudo service docker stop
- Copied the whole /var/lib/docker directory to the hard driver’s docker directory
- Deleted the /var/lib/docker directory
- Created the symbolic link “docker” in /var/lib that point to the docker directory on the USB drive
- sudo mount -a
- sudo service docker start
This fixed the disk space problem and the build command succeeded in building the container with dependencies to build the binaries. The next step was to build the binaries by running the command:
sudo make binary
Running out of Memory
The build failed during the compiling phase complaining “out of memory” error. So I created a 2G swap file to fix this issue:
dd if=/dev/zero of/media/usbdrive/swap/swapfile bs=1M count=2000 chmod 600 /media/usbdrive/swap/swapfile mkswap /media/usbdrive/swap/swapfile swapon /media/usbdrive/swap/swapfile
I then encountered yet another issue.
The build was restarted and it came to a place where it executed a docker run command with lots of parameters followed by the warning:
#WARNING: I don't seem to be running inside a container... ...
This is quite unexpected as I thought the build was run inside the container created earlier!!!
Then it failed with make error: 1 when I reached places where it tried to use “go” to continue the build and resulted in “Signal: Killed”. I could not find any logs that could tell me what went wrong. I retried several times with the same result. I thought to myself that since go was involved, let me see what version of go was installed on my Odroid-C2. Maybe it was the wrong version? It turned out that go was not installed. So I installed it:
sudo apt-get update sudo apt-get install golang
Then I ran the build again and after a tantalising 20 minutes or so, the build was completed successfully.
The build created 1 directory for the client (~/docker/bundles/1.12.0/binary-client ) and 1 for the daemon (~/docker/bundles/1.12.0/binary-daemon ). To test out the newly built binaries, do the following:
sudo -s services docker stop PATH=pathOfDaemonDirectory:$PATH cd pathOfDaemonDirectory ./dockerd
From another virtual terminal, execute from pathOfClientDirectory:
./docker info shows "Server Version: 1.12.0".
I also ran the busybox httpd image in a container to make sure that it worked. This is the same test I ran in my previous article.
Summary: Making a Successful Build
Here is a summary of what needed to be done to make a successful docker 1.12.0 build on my Odroid-C2 after cloning the docker repository from github:
(Note: You must have installed the docker.io package (I had v1.11 installed on may Odroid-C2) before you start the build.)
- Comment out the –add-architecture RUN command in the Dockerfile.aarch64 docker file
- Add a hard drive and move the /var/lib/docker directory to your hard drive if you are using a 8G SD card
- Create a swap partition or swap file on your hard drive
- Install go on your Odroid-C2
The you can proceed to run the following commands from your docker directory:
sudo make build sudo make binary
Now you know how to build Docker 1.12 on your Odroid-C2 from source. In the next instalment, I shall explore the Docker 1.12 built-in swam mode in forming a cluster using my 5 Odroid-C2s. So, stay tuned.