Docker on IoT: Mind the Gap of ARM Architecture

The development of IoT has seen a rise of Docker on single-board computers for the ease and consistency of service deployment. The fact that most of the devices are built upon ARM architecture can pose a challenge to the usage of Docker in an IoT setting.

What is ARM Architecture?

ARM is the prevailing architecture for CPUs on single-board computers, because it is designed to reduce cost, power consumption and heat dissipation.

ARM architecture features a different set of processor instruction than its desktop counterpart (x86_64 architecture). ARM processors work on RISC, reduced instruction set computing, while desktop processors (e.g., Intel, AMD, etc.) work on CISC, complex instruction set computing.

The difference on processor instruction set implies that an application in the form of byte-code cannot simultaneously run on both architectures. To support both of them, the application has to be compiled from source code into two versions of byte code to be run on either desktop or ARM.

In real world, there exists more types of architecture, so to be cross-platform, the distributor of application has to prepare multiple versions, as such:

Package perl on Alpine Linux catalogue supports seven types of architecture.

As can be seen above, there are even different types of architecture inside the ARM family. Thus first things first, it is important to know which architecture the IoT hardware will be based on.

Well, Docker Installer doesn’t work out of box…

Docker provides an easy install command on get.docker.com that generally works really well, but it can fail on certain boards and operating systems.

For example, the Docker install command fetches the package on ARMv7 architecture when invoked from any Raspbian operating system on Raspberry Pi. But if you are on a Pi Zero or Pi Zero W, the fetched Docker package won’t start because they are running on ARMv6 architecture.

As Docker is open-source software, it is possible to compile it from source on an ARMv6 board to set it up. However, this would negate the benefits we expect from using Docker—an easy and consistent deployment.

Fortunately, for certain popular boards, there are third-party solutions. The most popular one for Raspberry Pi is Hypriot, a group of enthusiasts providing a well-packaged open-source image to set everything up when flashing the SD card: the operating system, Docker, docker-compose, git, etc.

If such a solution doesn’t exist for your board of selection, it might be worth to either reconsider the hardware stack, or go building your own image, depending on the scale of project.

My containers doesn’t run… got an “exec format error”?

One of the nastiest parts working with IoT and hardware is debugging, because issues can happen at the deepest in the stack, leading to error messages that are hard to trace.

Keep in mind that a Docker image is always built upon a specific architecture, although the desktop ones don’t emphasize that they only run on x86_64 platform. While it is possible to pull regular Docker images onto an ARM platform without errors, they will never be run but throwing an “exec format error.”

Fortunately, if the image you intend to use is built upon a common one, such as debian or alpine, there are ARM-dedicated organizations on Docker Hub providing their counterparts:

To rebuild a Docker image on a common one, it may simply work by prefixing the “FROM” line with the target architecture, for example, replacing “FROM alpine” to “FROM arm32v7/alpine.” The major Linux distros provide packages for nearly all architectures and a rebuild or recompile usually work without any issues.

It is to note that there are deprecated architectures on Docker Hub, such as armhf (https://hub.docker.com/u/armhf) to be replaced by arm32v6 and arm32v7. Deprecated images are outdated and unmaintained.

Published by

Ling YANG

Lead consultant at Studio theYANG, an independent web software consulting studio from Montreal, Canada focused on maintenance and support of Python and Linux systems.

Leave a comment