Docker on Raspberry Pi - Installation Guide

Docker has become an indispensable tool for developers, allowing them to easily create, deploy, and run applications in containers. While Docker is commonly used on desktops and servers, it can also be installed on embedded devices such as the Raspberry Pi. This guide walks through the complete installation process and demonstrates practical usage with examples.

Hardware Requirements

Docker can run on any Raspberry Pi model, but performance varies significantly. The Raspberry Pi 4 with 4GB or 8GB of RAM provides optimal performance compared to older models like the Pi 3B+.

Recommended hardware specifications

  • Raspberry Pi 4 with 2GB or more RAM

  • MicroSD card with at least 16GB of storage

  • Power supply with at least 3A output

  • Ethernet cable or Wi-Fi connectivity

Docker Installation Process

Step 1 Update System Packages

Before installing Docker, update the Raspberry Pi to ensure you have the latest software and security patches

sudo apt update
sudo apt upgrade -y

Step 2 Install Docker

Use the official Docker installation script to download and install the latest version

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

This command automatically detects the ARM architecture and installs the appropriate Docker version for Raspberry Pi.

Step 3 Add User to Docker Group

To run Docker commands without sudo, add your user to the docker group

sudo usermod -aG docker $USER

Log out and back in for the group changes to take effect, or restart the Pi.

Step 4 Verify Installation

Test the Docker installation by running the hello-world container

docker run hello-world

If successful, you'll see a "Hello from Docker!" message confirming the installation.

Running Your First Container

Let's deploy a simple web server using the popular Nginx image to demonstrate Docker functionality.

Pull and Run Nginx Container

Download the Nginx image and run it as a container

docker pull nginx
docker run -d -p 80:80 --name my-nginx nginx

The -d flag runs the container in detached mode, while -p 80:80 maps port 80 from the container to the Pi's port 80.

Find your Pi's IP address to access the web server

hostname -I

Navigate to the IP address in your browser to see the Nginx welcome page.

Creating Custom Docker Images

For specific requirements, create custom images using a Dockerfile. Here's an example that builds a lightweight Nginx server

FROM alpine:latest

RUN apk update && \
    apk add nginx && \
    mkdir -p /run/nginx

COPY index.html /usr/share/nginx/html/

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

Build the custom image

docker build -t my-custom-nginx .

Run a container from your custom image

docker run -d -p 8080:80 --name custom-nginx my-custom-nginx

Container Management

Essential commands for managing Docker containers

Command Purpose
docker ps List running containers
docker ps -a List all containers
docker stop <container> Stop a running container
docker rm <container> Remove a stopped container
docker images List all images
docker rmi <image> Remove an image

Clean up resources when finished

docker stop my-nginx
docker rm my-nginx
docker rmi nginx

Conclusion

Docker on Raspberry Pi enables efficient application deployment and management in containerized environments. This setup is particularly valuable for IoT projects, home automation, and learning containerization concepts. The combination of Docker's portability with Pi's affordability creates an excellent platform for development and experimentation.

Updated on: 2026-03-17T09:01:38+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements