How to Install Docker and Docker-Compose on Raspberry Pi

How to Install Docker and Docker-Compose on Raspberry Pi

This article mainly demonstrates the process of installing Docker and Docker-compose on Raspberry Pi.

Hardware: Raspberry Pi 3B+

System version:

Linux raspberrypi 5.15.76-v7+ #1597 SMP Fri Nov 4 12:13:17 GMT 2022 armv7l GNU/Linux

Testing date: December 12, 2022

Installing Docker

1. Update the system

First, it is necessary to keep the system updated for installation. Run the following command in the command line to update the Raspberry Pi system:

sudo apt-get update && sudo apt-get upgrade

2. Download the Docker installation script

Download the appropriate script to install Docker in the Raspberry Pi environment by entering the following command in the command line:

curl -fsSL https://get.docker.com -o get-docker.sh

How to Install Docker and Docker-Compose on Raspberry Pi

3. Run the installation script

Once the download is complete, run the script to automatically complete the installation. Enter the following command in the command line:

sudo sh get-docker.sh

How to Install Docker and Docker-Compose on Raspberry Pi

After a moment, you will see the following information indicating that the installation was successful.

How to Install Docker and Docker-Compose on Raspberry Pi

4. Check the Docker version

Enter the following command in the command line:

docker version

How to Install Docker and Docker-Compose on Raspberry Pi

5. Run Docker hello-world

After installation, you can run a hello-world Docker image to experience Docker. If the hello-world image is not present locally, it will be downloaded automatically. Enter the following command in the command line:

sudo docker run hello-world

After running, you will see the following information, proving that everything is ready, and you can start your Docker journey.

How to Install Docker and Docker-Compose on Raspberry Pi

Check how many Docker images are installed locally

Here is a commonly used Docker command, docker images, which lists how many Docker images are installed in the system and how much space they occupy. For example, using -a allows you to view the Docker image list. Enter the following command in the command line:

sudo docker images -a

How to Install Docker and Docker-Compose on Raspberry Pi

Introduction to the Docker images command:

Docker images: List local images. Syntax:

docker images [OPTIONS] [REPOSITORY[:TAG]]

OPTIONS explanation:

  • -a: List all local images (including intermediate image layers; by default, intermediate image layers are filtered out);

  • –digests: Display the digest information of the images;

  • -f: Display images that meet conditions;

  • –format: Specify the template file for the return value;

  • –no-trunc: Display complete image information;

  • -q: Only display image IDs.

Add a non-root user to the Docker group

According to the Raspberry Pi process, any user with administrative privileges can be considered a root user and can execute containers.

For example, if the user is not logged in as root, they need to use the sudo prefix.

We can also add a non-root user to the Docker group, allowing them to run Docker commands directly without adding sudo before the Docker command.

Below is the syntax for adding a user to the Docker group.

sudo usermod -aG docker [user_name]

For example, to add the default user Pi in Raspbian, you can refer to the command below:

sudo usermod -aG docker pi

Then, restart with sudo reboot

Installing Docker-compose

Install using apt-get

Directly use the following command in the command line to install:

sudo apt-get install docker-compose

How to Install Docker and Docker-Compose on Raspberry Pi

Do not recommend installing with PIP3

It is not recommended to use pip3 to install docker-compose

pip3 install docker-compose # Not recommended because it will cause errors

The following error will be prompted ERROR: Failed building wheel for bcrypt

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for bcrypt
Failed to build bcrypt
ERROR: Could not build wheels for bcrypt, which is required to install pyproject.toml-based projects

Leave a Comment

×