Skip to content

Installing Docker and Docker Compose on a Raspberry Pi

Running containers on a Raspberry Pi is a great way to run lightweight, isolated applications without the overhead of installing them directly on Raspbian. Here, we'll guide you through the steps to install Docker and Docker Compose on your Raspberry Pi, ensuring that you can take full advantage of containerized applications.

Prerequisites

  • A Raspberry Pi with Raspbian OS installed.
  • An internet connection.
  • Terminal access to your Raspberry Pi.

Step-by-step Installation Guide

Step 1: Update and Upgrade Raspbian OS

Before installing any new software, it's always a good practice to update and upgrade your existing packages:

sudo apt update
sudo apt upgrade -y

Step 2: Install Docker on Raspberry Pi

Docker provides an installation script that simplifies the process of getting Docker on Raspberry Pi.

# Download and run Docker installation script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Add 'pi' user to the 'docker' group
sudo usermod -aG docker pi

You can verify that Docker was installed correctly:

docker --version

Step 3: Install Docker Compose

Docker Compose doesn’t come installed with Docker. Installing Docker Compose on a Raspberry Pi requires a slightly different approach compared to a standard Linux machine because of the Pi's ARM architecture.

First, we'll install required dependencies:

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

Now, install Docker Compose using pip:

sudo pip3 install docker-compose

To confirm the successful installation of Docker Compose:

docker-compose --version

Step 4: Test Your Installation

To make sure that both Docker and Docker Compose are working as expected, let's run a test container:

# Pull and run a basic 'hello-world' Docker image
docker run hello-world
The output should indicate that Docker is working correctly.

For Docker Compose, create a simple `docker-compose.yml file:

nano docker-compose.yml

Paste the following content:

docker-compose.yml

version: '3'
services:
  hello-world:
    image: hello-world

Now, run the composition:

docker-compose up

You should see Docker Compose starting the hello-world service and the same hello message from Docker.

Step 5: Clean Up (Optional)

If you wish to clean up after the test, you can remove the downloaded images:

docker rmi hello-world

Conclusion and Alternatives

By following these steps, you've successfully installed Docker and Docker Compose on your Raspberry Pi. Now, you're all set to explore the world of containerized applications with Docker on Raspbian. With the rising popularity of using Docker on Raspberry Pi, the opportunities for development and deployment are vast. Whether for home automation, IoT projects, or lightweight web servers, you've unlocked a versatile tool in your Raspberry Pi toolkit. If you want to use containers on a whole fleet of devices you might need further container automation. Here we can help you with automated installations but also very granular and simple docker-compose automation.