How to install Docker and Docker Compose on Raspberry Pi

How to install Docker and Docker Compose on Raspberry Pi

What is Docker?

Docker Engine is an open source containerization technology for building and containerizing your applications. Docker Engine acts as a client-server application with

Docker Engine installation overview
Lists the installation methods

Install Docker on Raspberry Pi

The Short Path

If you are running debian based OS on your Pi, the easy way to install docker is with below automated script.

curl -fsSL | sh

This is far easier than previous ways, which relied on a very manual process which often meant building Docker from scratch on a Raspberry Pi. This process could take hours.

Once Docker is installed using the above command, there are still a few manual steps that are needed to get the best experience on the device. The first is to set Docker to auto-start every time the Raspberry Pi is turned on or rebooted. To do this, the following command is needed:

The Long Path

Let's say, you are running any other OS apart from raspbian or ubuntu, Or you may want to install the package manually, here is the steps.

Set up the repository

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

$ sudo apt-get update

$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \

Add Docker’s official GPG key:

$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Use the following command to set up the repository:

$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine

This procedure works for Debian on x86_64 / amd64, armhf, arm64, and Raspbian.

Update the apt package index:

$ sudo apt-get update
Receiving a GPG error when running apt-get update?

Your default umask may be incorrectly configured, preventing detection of the repository public key file. Try granting read permission for the Docker public key file before updating the package index:
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
$ sudo apt-get update

Install Docker Engine, containerd

sudo apt-get install docker-ce docker-ce-cli

To install a specific version of Docker Engine, start by list the available versions in the repository:

To install a specific version of Docker Engine, start by list the available versions in the repository:

# List the available versions:
$ apt-cache madison docker-ce | awk '{ print $3 }'


Select the desired version and install:

$ VERSION_STRING=5:18.09.0~3-0~debian-stretch
$ sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING docker-compose-plugin

Add your user to the Docker group (Optional)

In order to run the docker without sudo, you need to add the user to dockergroup

sudo usermod -aG docker $USER

$USER replace with your username. Once done you must logout and log back in to take this effect

Test Docker Installation

Now in order to verify that Docker is installed correctly. You can check the Docker version by running the following command:

docker version

or you can run the test docker image with below command

docker run hello-world

Install Docker Compose

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

You can install docker-compose in two method, either as plugin or with python-pip package.

Install the Compose plugin

Update the package index, and install the latest version of Docker Compose:

sudo apt-get update
sudo apt-get install docker-compose-plugin

Verify that Docker Compose is installed correctly by checking the version.

$ docker compose version
Docker Compose version vN.N.N

Install using Python3 and Pip3

Docker-Compose usually gets installed using pip3. For that, we need to have python3 and pip3 installed. If you don't have it installed, you can run the following commands:

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

Once python3 and pip3 are installed, we can install Docker-Compose using the following command:

pip3 install docker-compose

check docker-compose version by running below command

docker-compose --version

Note : If you are installed docker-compose as plugin, you may need to use the compose command like docker compose up or docker compose down.If you follow the pip3 method the commands are docker-compose up or docker-compose down (Note there is a "-" between the words)

Enable the Docker system service

This is a very important addition. With the following command you can configure your Raspberry Pi to automatically run the Docker system service, whenever it boots up.

sudo systemctl enable docker

Find Raspberry Pi Docker Images

Raspberry Pi is based on ARM architecture. Hence, not all Docker images will work on your Raspberry Pi. Apply the Architectures filter (arm) to search for supported apps from Docker Hub.

How to Upgrade Docker on Raspberry Pi?

you can upgrade docker engine simply by running

sudo apt-get update && upgrade

Happy containerizing ;)