[Raspberry Pi] Installing Docker and Docker Compose on Raspberry Pi OS

At the end of May 2020, the Raspberry Pi Foundation announced Raspberry Pi OS, the new official operating system for the mini-computer that is replacing Raspbian.

The good news is that Raspberry Pi OS does support Docker and Docker Compose, in both the 32-bit and 64-bit variants! Read below on how to install it as well as Docker Compose.

Installation

Installing Docker

Installing Docker CE (Community Edition) on the Raspberry Pi OS requires running just a few commands.

The best way to install Docker is to fetch it from the official Docker repositories, so to ensure that you’re always running the latest version.

To install Docker CE on Raspberry Pi OS, both 32-bit and 64-bit, run:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Install some required packages first
$ sudo apt update
$ sudo apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common

# Get the Docker signing key for packages
$ curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -

# Add the Docker official repos
$ echo "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list

# Install Docker
$ sudo apt update
$ sudo apt install -y --no-install-recommends \
docker-ce \
cgroupfs-mount

Done! At this point, we just need to run two more commands to have the Docker service started and automatically launched at boot.

1
2
$ sudo systemctl enable docker
$ sudo systemctl start docker

Now that we have Docker running, we can test it by running the “hello world” image:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ sudo docker run --rm hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm32v7)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

Install Docker Compose

Lastly, let’s look at how to add Docker Compose.

Docker Compose is normally installed from pre-built binaries, downloaded from the GitHub release page for the project. Sadly, those are not available for the ARM architecture.

We can however install Docker Compose from pip:

1
2
3
4
5
6
7
# Install required packages
sudo apt update
sudo apt install -y python3-pip libffi-dev

# Install Docker Compose from pip (using Python3)
# This might take a while
sudo pip3 install docker-compose

With this, you now have a complete Raspberry Pi mini-server running Docker and ready to accept your containers.

1
2
3
4
5
$ docker-compose version
docker-compose version 1.27.4, build unknown
docker-py version: 4.4.1
CPython version: 3.7.3
OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019

References

[1] Docker and Docker Compose on Raspberry Pi OS | With Blue Ink - https://withblue.ink/2020/06/24/docker-and-docker-compose-on-raspberry-pi-os.html

[2] Empowering App Development for Developers | Docker - https://www.docker.com/

[3] Overview of Docker Compose | Docker Documentation - https://docs.docker.com/compose/