Setup Docker on RPi5

A detailed guide on how to setup Docker on RPi5.

Introduction

  1. I assume you already have a working default RPi5 setup.
  2. The end result of this procedure is a headless RPi5. It only needs a power supply and a network connection. (For servers I prefer hardwired network connections over wireless network connections.)
  3. The RPi5 will function as a server. So it's best to assign a fixed IP address.
  4. Since my initial password is quite simple, the procedure also contains a step to change the password. This way I can use a password manager (like KeePass) to remember the new, complex password. This can be skipped if you already use a strong password.
  5. If you don't need VLANs, you can skip that step.

Install the latest updates

Open a terminal and execute the following commands in order. (The 2nd command is not required, but I always like to know what will get updated.)

$ sudo apt update
$ sudo apt list --upgradable
$ sudo apt full-upgrade

If you want to go full auto for updating you can also execute the following line in a terminal instead.

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

Install remote desktop on RPi5

Execute the following command in a terminal:

$ sudo apt install xrdp

Connect to your RPi5 using the Windows RDP client

You can easily find the Windows RDP client in the Start menu by searching for Remote Desktop Connection.

ℹ️ An excellent guide with screenshots on how to do this: How to Setup Raspberry Pi Remote Desktop.

Enter the IP address of your RPi5 and click Connect. You should now be connected and see the screen of your RPi5.
Leave the session on Xorg.
Enter your credentials and log on to the RPi5.

Change password

ℹ️ This can be skipped if you already use a strong password.

Execute the following command in a terminal:

$ passwd
The system will first ask for your current password. Type it in and hit Enter.
Then the system asks for your new password. Type it in and hit Enter.
Now the system asks to confirm your new password. Type it again and hit Enter.

The final output looks somewhat like this:

Changing password for <user>.
Current password:
New password:
Retype new password:
passwd: password updated successfully

Switch to X11 Desktop Backend

Since xrdp does not support the default Wayland display server, we'll switch to X11. We'll use raspi-config to accomplish this.

ℹ️ An excellent guide with screenshots on how to do this: Switching Between Wayland and X11 on a Raspberry Pi.
Since the guide is several years old, the numbers of the menu options might be different as this is linked to the RPi OS version.

Execute the following command in a terminal:

$ sudo raspi-config

Navigate to Advanced Options - A7 Wayland.
Select X11 to enable it.
Finish and reboot.

Configure VLANs

ℹ️ This can be skipped if you don't require VLANs.

Install the required package

Execute the following commands in a terminal:

$ sudo apt update
$ sudo apt install vlan

Start tagged VLAN support upon boot

Execute the following commands in a terminal:

$ sudo -i
$ echo "8021q" >> /etc/modules
$ exit

Check the current network configuration of the RPi5

You can use the following commands in a terminal to check your current network configuration ad connections:

$ ip a
$ nmcli device status
$ nmcli con show
$ ip link show

Obviously, this step can be skipped if you already know your network configuration.

Create VLAN connection

⚠️ This step has to be executed for every VLAN you need to support.

The following command assumes the following information:

Property Value
VLAN name VLAN-3
Interface name eth0.3
Device eth0

ℹ️ As mentioned earlier: I use the ethernet connection.

VLAN ID 3
IPv4 address 192.168.3.2
IPv4 gateway 192.168.3.1

$ sudo nmcli con add type vlan con-name 'VLAN-3' ifname eth0.3 dev eth0 id 3 ipv4.addresses 192.168.3.2/24 ipv4.gateway 192.168.3.1 ipv4.method manual autoconnect yes

Activate VLAN connection

⚠️ This step has to be executed for every VLAN you need to support.

Execute the following command in a terminal:

$ sudo nmcli con up VLAN-3

Prepare for Docker setup

Add Docker's official GPG key

Execute the following commands in a terminal:

$ sudo apt update
$ sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
$ sudo chmod a+r /etc/apt/keyrings/docker.asc

Add the repo to Apt resources

Execute the following commands in a terminal:

$ sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
$ sudo apt update

Install Docker

Execute the following command in a terminal:

$ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Add user to docker group

Verify if your user is already a member of the docker group. (This normally isn't the case yet.)
Execute the following command in a terminal:

$ groups

Execute the following command in a terminal to add your user to the docker group:

$ sudo usermod -aG docker $USER

Reboot

Execute the following command in a terminal:

$ sudo reboot

Test Docker

Execute the following commands in a terminal:

$ docker ps
$ docker run hello-world

✅ Congratulations: You already have a working Docker setup.
In the next steps we'll install a GUI to make it easier to manage your Docker instance as it doesn't require you to learn the CLI commands. The beauty of it is that the management GUI is itself a Docker container.

Install Portainer

ℹ️ Some background info:

  1. When you pull images from Docker Hub and don't specify a version, Docker always pulls the image with the tag latest.
    I generally use a specific version as this makes it easier to identify your current version. I also tend to include the used version in the container name for convenience.
  2. Since I'm using VLANs I don't want Portainer to be exposed to all VLANs and IP addresses assigned to the RPi5. That's why I included the Pi's IP address for the VLAN I want to access it from when assigning the ports.

Execute the following commands in a terminal:

$ docker pull portainer/portainer-ce:2.45.0
$ docker run -d -p 192.168.3.2:8000:8000 -p 192.168.3.2:9443:9443 --name=portainer_2.45.0 --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:2.45.0

Access Portainer

Open a browser on your Windows PC and go to https://192.168.3.2:9443

ℹ️ Portainer setup: An excellent getting started guide for Portainer is: Installing Portainer to the Raspberry Pi.