Docker on Raspberry Pi4
Installing Docker on Raspberry Pi is a great way to turn your Pi into a lightweight container server.
Running Docker on a Raspberry Pi 4 turns your tiny board into a powerful containerized platform. Whether you’re hosting a personal project, testing microservices, or automating your home network, Docker makes deployment easy and repeatable. In this guide, I’ll show you how I installed Docker on Ubuntu 22.04 running on my Raspberry Pi 4, and I’ll share the essential commands I use to manage containers daily.
Prerequisites
- Raspberry Pi 4 with Ubuntu 22.04 (64-bit) installed
- Internet access
- User with sudo privileges
- SSH access
Step-by-Step: Install Docker on Raspberry Pi 4
1. Update the system
sudo apt update && sudo apt upgrade -y
2. Install Docker on Raspberry Pi using the Official Repository
# Installs essential packages:
# - ca-certificates: enables secure HTTPS connections
# - curl: tool for transferring data from URLs (used to download files)
# - gnupg: provides encryption and signing tools (needed for verifying downloaded packages)
sudo apt install -y ca-certificates curl gnupg
# Add GPG Key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Add Docker Repository for Ubuntu
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3. Check Docker Installation
docker --version
docker compose version
Output of the commands:
root@pi4:~# docker version
Client: Docker Engine - Community
Version: 28.2.2
API version: 1.50
Go version: go1.24.3
Git commit: e6534b4
Built: Fri May 30 12:07:29 2025
OS/Arch: linux/arm64
Context: default
Server: Docker Engine - Community
Engine:
Version: 28.2.2
API version: 1.50 (minimum version 1.24)
Go version: go1.24.3
Git commit: 45873be
Built: Fri May 30 12:07:29 2025
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.7.27
GitCommit: 05044ec0a9a75232cad458027ca83437aae3f4da
runc:
Version: 1.2.5
GitCommit: v1.2.5-0-g59923ef
docker-init:
Version: 0.19.0
GitCommit: de40ad0
root@pi4:~# docker compose version
Docker Compose version v2.36.2
4. Start and Enable Docker Service
# Start the Docker service immediately
sudo systemctl start docker
# Enable the Docker service to start automatically at system boot
sudo systemctl enable docker
5. Run Docker Test Container to Verify Installation
After checking the Docker and Docker Compose versions, you can run a simple test container to verify that Docker is working correctly:
# Run Docker test container to verify everything works
sudo docker run hello-world
If everything is set up properly, you should see an output similar to this:
root@pi4:~# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c9c5fd25a1bd: Pull complete
Digest: sha256:0b6a027b5cf322f09f6706c754e086a232ec1ddba835c8a15c6cb74ef0d43c29
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
This confirms that your Docker engine is installed and functioning properly on your Raspberry Pi 4.
5. (Optional) Add Your User in The Docker Group
sudo usermod -aG docker $USER
Useful Docker Commands
Once Docker is installed, here are the commands I use most often to work with containers and images.
ommand | What It Does |
---|---|
docker version | Show Docker version |
docker info | Show system-wide Docker info |
docker pull <image> | Download a Docker image |
docker images | List all downloaded images |
docker run -d --name <name> <image> | Run a container in detached mode |
docker ps | Show running containers |
docker ps -a | Show all containers (including stopped) |
docker stop <container> | Stop a running container |
docker rm <container> | Remove a container |
docker rmi <image> | Remove a Docker image |
docker exec -it <container> bash | Access an interactive shell inside a running container |
docker network ls | List all Docker networks |
nano docker-compose.yaml | Create or edit a docker-compose.yaml file |
docker compose up -d | Start all services defined in the Compose file in detached mode |
docker compose down -v | Stop and remove services, including volumes |
docker logs <container> | View logs from a running container |
docker exec -it <container> sh | Access a shell inside a container (useful when Bash is not available) |
Installing Docker on Raspberry Pi 4 with Ubuntu 22.04 is quick, and it unlocks powerful tools for automation, app hosting, and experimentation. With just a few commands, your Pi becomes a flexible server for anything from file sharing to web hosting.
In future articles, I’ll cover:
- My favorite containers to run on Raspberry Pi
- Using Docker Compose for persistent setups
- Managing Docker with Portainer GUI