Skip to content

How to install docker and docker-compose on your Raspberry Pi

raspberry pi and docker

These are the steps on how to install docker and docker-compose on your Raspberry Pi, so you can take advantage of containerization of applications and services.

This assumes that you have a Raspberry Pi 3 or 4 running the latest version of Raspberry Pi OS (previously called Raspbian).

Firstly we will ensure that our operating system is updated, or at least that the repositories sources are updated.

Update repositories sources

sudo apt-get update

Update OS packages (recommended but not necessary)

sudo apt-get upgrade

Installation of docker

We will use the convenience script that docker provides to install docker on our Raspberry Pi. To do this we simply execute the following command:

sudo curl -sSL https://get.docker.com | sh

And that’s it all. If you want to execute docker commands as a non root user, is recommended to add your user to the docker group. For example, for the user ‘pi’ you can execute

sudo usermod -aG docker pi

You can test if docker has been properly installed checking its version. Also you can ask for a list of containers, what should output an empty container list.

jere@dockertest01:~$ docker -v
Docker version 19.03.8, build afacb8b7f0
jere@dockertest01:~$ docker ps -a
CONTAINER ID        IMAGE                                        COMMAND                  CREATED             STATUS                 PORTS            NAMES

Installation of docker-compose

We will be installing docker-compose using pip3, so you need to have pip3 installed prior to install docker-compose. To install pip3 you have two alternatives:

  • Follow the official pip installation method to install the latest pip3 version. This method consists in execute the command below:
sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && sudo python3 get-pip.py
  • Install pip3 from the repositories provided in Raspberry Pi OS. This implies install/remove some dependencies and finally install pip3 with the package from the OS repository.
sudo apt-get install -y libffi-dev libssl-dev
sudo apt-get install -y python3 python3-pip
sudo apt-get remove python-configparser

Choose the option from above that best suits your needs.

After that, docker-compose installation becomes as simple as execute this command in our terminal:

sudo pip3 -v install docker-compose

Done! We can check if docker-compose is properly installed checking its version with ‘docker-compose -v’. This will output something similar to this:

docker-compose version 1.25.5, build 8a1c60f6

In this post we have learned how to install docker and docker-compose in your Raspberry Pi. In case you use Ansible, check out our post how-to-install-docker-and-docker-compose-on-your-raspberry-pi-with-ansible. If you have any doubt, let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *