Running Docker on Raspberry Pi: A Comprehensive Guide
Ohidur Rahman Bappy
MAR 22, 2025
Running Docker on Raspberry Pi: A Comprehensive Guide
Installing Docker
To install Docker on your Raspberry Pi, run the following command:
curl -sSL https://get.docker.com | sh
Adding Non-root User to Docker Group
Add the current user to the Docker group to execute Docker commands without sudo
:
sudo usermod -aG docker $USER
Installing Docker Compose
You can install Docker Compose using pip:
sudo pip3 -v install docker-compose
Configuring Docker to Start on Boot
Enable Docker services to start automatically upon boot:
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
To disable this behavior, replace enable
with disable
:
sudo systemctl disable docker.service
sudo systemctl disable containerd.service
Pulling and Running Images
Pull the Hello World image to verify your Docker installation:
docker pull hello-world
Run it using:
docker run hello-world
docker exec -it CONTAINER_NAME sh
# Now you can enter commands in the container
Managing Containers and Images
Listing Containers
To list all running containers:
docker ps
Listing Images
List all available images:
docker image ls
List image IDs only:
docker image ls -aq
Building an Image
Build an image from a Dockerfile in the current directory:
docker image build -t IMAGE_NAME:BUILD_NUMBER .
Stopping and Removing Containers
Stop a specific container:
docker stop CONTAINER_ID
Stop all running containers:
docker stop $(docker ps -aq)
Remove a specific container:
docker rm CONTAINER_ID
Remove all containers:
docker rm $(docker ps -aq)
Setting Restart Policies
Define container restart policies:
--restart options:
- no: Do not automatically restart the container (default).
- on-failure: Restart the container on error (non-zero exit code).
- always: Always restart unless manually stopped.
- unless-stopped: Restart unless user stopped.
Basic Docker Commands
Here's a list of common Docker commands and their descriptions:
Command Description
- docker attach: Attach to a running container.
- docker build: Build an image from a Dockerfile.
- docker commit: Create a new image from a container’s changes.
- docker exec: Run a command in a running container.
- docker ps: List containers.
- docker pull: Pull an image or a repository from a registry.
- docker push: Push an image or a repository to a registry.
- docker rm: Remove one or more containers.
- docker run: Run a command in a new container.
- docker stop: Stop one or more running containers.
Managing Docker with Portainer
Creating a Volume
Create a volume for Portainer data:
docker volume create portainer_data
Starting Portainer
Run Portainer with a persistent data volume:
docker run -d -p 8000:8000 -p 9000:9000 \
--name=portainer --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /dkr/portainer_data:/data portainer/portainer-ce:latest
Working with Ubuntu Docker Image
Pull the Ubuntu Docker image:
docker pull ubuntu
Run it interactively:
docker run -it ubuntu
Managing Docker Volumes
List all volumes:
docker ps -a
Remove unused volumes:
docker rm -f <volume_name>
Sample Docker Projects
Installing Homer Dashboard
Run Homer Dashboard:
docker run --name=homer -d \
-p 8001:8080 \
-v /dkr/homer:/www/assets \
--restart=always \
b4bz/homer:latest
Installing VSCode CodeServer
version: "2.1"
services:
code-server:
image: lscr.io/linuxserver/code-server
container_name: code-server
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Dhaka
- PASSWORD=password #optional
- HASHED_PASSWORD= #optional
- SUDO_PASSWORD=password #optional
- SUDO_PASSWORD_HASH= #optional
- PROXY_DOMAIN=code.ohidur.com
- DEFAULT_WORKSPACE=/config/workspace #optional
volumes:
- /path/to/appdata/config:/config
ports:
- 8443:8443
restart: unless-stopped
Running Heimdall
docker run --name=heimdall -d --restart=always \
-v /dkr/heimdall:/config -e PGID=1000 -e PUID=1000 \
-p 8004:80 -p 8005:443 linuxserver/heimdall
Installing Webtop
version: "2.1"
services:
webtop:
image: lscr.io/linuxserver/webtop:ubuntu-mate
container_name: webtop
privileged: true #optional
security_opt:
- seccomp:unconfined #optional
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Dock
volumes:
- /dkr/webtop:/config
ports:
- 5001:3000
shm_size: "2gb" #optional
restart: unless-stopped
With this guide, you have the essential knowledge to effectively run and manage Docker on a Raspberry Pi. Happy Dockerizing!