Skip to content
GEEKnodes

Raspberry Pi

Docker on Raspberry Pi: Install It and Run Your First Containers

How to install Docker and Docker Compose on 64-bit Raspberry Pi OS, use it without sudo, run your first containers and protect your SD card.

Docker is the most convenient way to turn a Raspberry Pi into a home server. Each service (an ad blocker, a website monitor, a private cloud) lives in its own container, installs with one command and is removed without leaving traces on the system. In this guide we install Docker and Docker Compose, run the first containers and see how to look after the SD card.

In short

  • Use 64-bit Raspberry Pi OS (preferably Lite): almost all current images are arm64.
  • Install with the official script: curl -fsSL https://get.docker.com | sh.
  • Add your user to the docker group so you do not have to type sudo each time.
  • Define your services in a compose.yaml and start them with docker compose up -d.
  • If you will run several containers 24/7, boot from an SSD: the SD card suffers with so many writes.
Layers: Raspberry Pi hardware, operating system, Docker and three isolated containers on top
Each service lives in its own container, separate from the system and from the others.

What you need

Before starting, update the system:

sudo apt update && sudo apt full-upgrade -y

Step 1: install Docker

The simplest method, and the one Docker maintains, is its install script, which adds the official repository and installs the engine together with the Compose plugin:

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

If you prefer to review what it does before running it, open it with less get-docker.sh. When done, check the installation:

docker --version
docker compose version

Avoid installing the docker.io package from the Debian repositories alongside the official one: they are different versions and mixing them causes conflicts.

Step 2: use Docker without sudo

By default only root can talk to Docker. Add your user to the docker group:

sudo usermod -aG docker $USER

Close the SSH session and log in again for the change to take effect. Belonging to this group is effectively administrator access, so only do it with your own user.

Test that everything works:

docker run --rm hello-world

If you see “Hello from Docker!”, the engine is ready.

Step 3: your first service with Docker Compose

With docker run and a string of options it is easy to forget how you launched a container. Docker Compose keeps it all in a file. As an example we set up Uptime Kuma, a dashboard that watches whether your websites and devices are online.

Create a folder for the service and the compose.yaml file:

mkdir -p ~/docker/uptime-kuma && cd ~/docker/uptime-kuma
nano compose.yaml
services:
  uptime-kuma:
    image: louislam/uptime-kuma:1
    container_name: uptime-kuma
    ports:
      - "3001:3001"
    volumes:
      - ./data:/app/data
    restart: unless-stopped

Start it in the background:

docker compose up -d

Open http://YOUR-PI-IP:3001 in your browser and you will see the dashboard. What each line means:

KeyWhat it does
imageThe image to download. The tag (:1) pins the major version
portspi-port:container-port
volumesStores data in ./data, outside the container, so it is not lost
restart: unless-stoppedStarts the container again after a Pi reboot
The browser reaches the container on port 3001 and data is saved in the ./data folder, outside the container
The port opens the service to the browser; the volume keeps data outside the container.

Commands you will use daily

docker ps                      # running containers
docker compose logs -f         # follow logs live (Ctrl+C to quit)
docker compose pull            # download the new image version
docker compose up -d           # recreate the container with the new image
docker compose down            # stop and remove the container (data in ./data stays)
docker image prune             # delete old unused images

To update a service, just run docker compose pull followed by docker compose up -d inside its folder.

A graphical interface: Portainer

If you prefer to manage containers from the browser, Portainer is the most popular option:

services:
  portainer:
    image: portainer/portainer-ce:lts
    container_name: portainer
    ports:
      - "9443:9443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./data:/data
    restart: unless-stopped

Go to https://YOUR-PI-IP:9443 (the browser will warn about the self-signed certificate) and create the administrator user in the first few minutes: for security, Portainer closes the wizard if you take too long.

What else you can run

  • Pi-hole, to block ads across the whole network. There is the Pi-hole guide and it also exists as an official Docker image.
  • Home Assistant in a container. If you want add-ons and built-in backups, installing Home Assistant OS is more convenient.
  • WireGuard, to get into your home from outside. Here is the version with PiVPN.
  • Nextcloud, Jellyfin or Vaultwarden: private cloud, media server and password manager.

Before pulling an image, check on Docker Hub that it has a linux/arm64 version. Images that exist only for amd64 will not start and give an exec format error.

Look after the SD card

Containers constantly write logs and databases, and SD cards have a limited life. Three measures:

  1. Boot from an SSD. On the Pi 5 this is possible with an NVMe HAT: we explain it in booting the Raspberry Pi 5 from an NVMe SSD.
  2. Limit log size. Create /etc/docker/daemon.json with this content and restart Docker with sudo systemctl restart docker:
{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" }
}
  1. Back up the ~/docker folder, which holds all configuration and data. You can schedule it with cron or clone the whole card, as explained in backing up the SD card.
An SD card receives many writes and wears out; an SSD handles them much better
With many containers 24/7, an SSD beats the SD card.

Frequently asked questions

Does Docker work on 32-bit Raspberry Pi OS? Yes, but there are ever fewer armhf images and Docker has been dropping 32-bit support. For a new server, install the 64-bit version.

How many containers can a Raspberry Pi handle? It depends on what they do. A 4 GB Pi 4 or 5 easily runs ten or fifteen light services (Pi-hole, Uptime Kuma, WireGuard). Heavy ones, like Nextcloud or video transcoding in Jellyfin, need more memory and an SSD.

How do I access a service from outside home? The safest way is not to open ports and to get in through a VPN like WireGuard. If you decide to expose one, read first how to open ports on your router and put an HTTPS proxy in front.

Is data lost when I delete a container? No, if it is in a volume like ./data. The container is disposable; the data lives in the folder you mount.

Accessibility preferences

Quick profiles

Text and reading

Text size
Default
Line height
Default
Letter spacing
Default
Word spacing
Default

Colour

Motion and orientation

Cursor