/* raspi.dev */.

How to Install Docker on a Raspberry Pi: Step-by-Step Guide

Cover Image for How to Install Docker on a Raspberry Pi: Step-by-Step Guide
Tom
Tom

Getting Started

Docker is an essential tool for developers and hobbyists alike, enabling the deployment and management of applications in lightweight, portable containers. Installing Docker on a Raspberry Pi allows you to create a powerful, flexible development environment on a compact, energy-efficient device. In this guide, we’ll walk you through installing Docker on a Raspberry Pi.

Prerequisites

Before you begin, make sure you have the following:

  • A Raspberry Pi (preferably Raspberry Pi 3 or newer for better performance).
  • A microSD card with Raspberry Pi OS installed.
  • A stable internet connection.
  • SSH access or a monitor and keyboard connected to the Raspberry Pi.

Step 1: Update and Upgrade the System

First, ensure that your Raspberry Pi is up-to-date. Open a terminal or SSH into your Raspberry Pi and run:

sudo apt update && sudo apt upgrade -y

This command updates the package lists and installs any available upgrades.

Step 2: Install Required Packages

Docker installation requires certain dependencies. Install them with the following command:

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

Step 3: Download and Install Docker

Use the official Docker installation script to install Docker on your Raspberry Pi. Run the following command:

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

Then execute the script:

sudo sh get-docker.sh

This script will detect your system and install the appropriate version of Docker.

Step 4: Add Your User to the Docker Group

By default, Docker requires root privileges. To avoid using sudo with every Docker command, add your user to the Docker group:

sudo usermod -aG docker $USER

For this change to take effect, log out and log back in, or run:

newgrp docker

Step 5: Verify the Installation

Check if Docker is installed and running:

docker --version

You should see the Docker version installed. Then verify Docker is working correctly by running the following test container:

docker run hello-world

This command downloads and runs a test Docker image, confirming that Docker is functioning properly.

Step 6: Enable Docker to Start on Boot

To ensure Docker starts automatically when the Raspberry Pi boots, run:

sudo systemctl enable docker

Step 7: (Optional) Install Docker Compose

Docker Compose is a tool to define and manage multi-container Docker applications. To install Docker Compose, use the following command:

Download the latest version:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Make the binary executable:

sudo chmod +x /usr/local/bin/docker-compose

Verify the installation:

docker-compose --version

Conclusion

Congratulations! You’ve successfully installed Docker on your Raspberry Pi. You can now run and manage containers to host applications, create a local development environment, or explore the vast ecosystem of Docker images.

If you want to go further, consider setting up Docker Swarm to create a cluster of Raspberry Pi devices or explore Kubernetes for container orchestration.

Happy containerizing! 🚀