Here’s how to run Docker on IoT devices, which enables you to bring container-based app development to the edge.

February 3, 2021

4 Min Read
Training and Development on the Mechanism of Metal Gears. in the design of information related to business
Training and Development on the Mechanism of Metal Gears. in the design of information related to businessThinkstock

By Dan Sullivan

Running Docker on IoT devices offers advantages by bringing containers to the edge. In the following discussion, the focus is on implementation issues, starting with installation.

In life science research, biologists use model organisms such as mice to learn things that apply to similar organisms. In this exercise we’ll learn using a Raspberry Pi as our version of mice. Other devices may require a slightly different set of operations, but the principles are the same.

Installing Docker is almost trivial, thanks to the Docker install script available at get.docker.com.  From a command line on the device, update the package manager with the following code:

sudo apt update -y

Then, use curl to download Docker itself. The command for that is the following:

curl -sSL get.docker.com -o get-docker.sh && sh get-docker.sh

Curl is a command line utility for transferring data using any of  several protocols.  The parameters indicate the operation should display minimal log messages, (aka silent mode)but show error messages on a failure (-S), and follow any redirects if the page has moved.

The output of the curl command is written to the file get-docker.sh. The command finishes by running the get-docker.sh shell script, and that get-docker.sh downloads the appropriate Docker for the platform.

Once you download Docker, specify a user that will run Docker commands. To add permissions to the user pi (or some other user) so that it can run Docker, use this command:

Sudo usermod -aG docker pi

This adds the user pi to the docker group.  At this point, you should be able to successfully run the Docker hello-world service to verify that the installation succeeded with the following command:

docker run hello-world

Docker allows you to build images and run containers, which are time savers when developing applications for the cloud and the edge. Typically, the ratio is to run one service per container but many applications require multiple services and therefore multiple containers.  The tool for managing the deployment of multiple containers is called Docker Compose.  Docker Compose is written in Python and has some library dependencies, which need to be installed. The command is the following:

sudo apt-get install -y libffi-dev libssl-dev

will install a foreign function call library and an ssl library.  You will also need to install Python 3 with this command:

sudo apt-get install -y python3 python3-pip

With all the dependencies in place, the next step is to install Docker Compose with this command:

sudo pip3 install docker-compose

The device is now ready to run Docker images. Images can either be downloaded from a repository or built from a base image.  When you run Docker on IoT devices, it’s critical to use images that are built for the platform of the IoT device. Raspberry Pi, for example, is built on the ARM platform, so it doesn’t support images created for Intel or AMD architectures.

Docker images are available within the Docker registry. When searching for images, include the term “ARM” in the search string. ARM images will have names such as “arm64v8/alpine” or “arm32v6/alpine.”

For developers who want to deploy their own application using Docker, start with a base image and build on that.  Since resources on IoT devices are limited, it is best to start with a small, minimalist image. Alpine is a lightweight Linux distribution that is used widely as a base image for Docker containers. The potential drawback of using a lightweight operating system is that you need to install a number of dependencies. They may be available by default in other Linux distributions.

If you are interested in working with Raspberry Pis, consider using HypriotOS, which is specifically designed to get Docker up and running on the platform as fast as possible. The open source project includes raw images, a tool to flash SD card images and support for Docker Compose.

BalenaOS is another host operating system tailored for Docker with a focus on IoT and cloud support. This is a minimal Linux distribution, which keeps the OS footprint small, but it also supports networking in harsh or unreliable conditions. BalenaOS is based on Yocota Linux, a distribution designed for customized embedded systems.

Enterprises are increasingly adopting Docker because it supports distributed, dynamic, and complex applications.

 

Sign Up for the Newsletter
The most up-to-date news and insights into the latest emerging technologies ... delivered right to your inbox!

You May Also Like