How to Install Docker on Ubuntu – Step-by-Step Guide
Discover how to set up Docker on Raspberry Pi and start deploying apps in containers quickly.
Introduction
Docker is one of the most popular platforms for running applications inside lightweight, isolated environments called containers. Instead of installing software directly on your system, containers let you bundle everything an app needs (code, libraries, dependencies) so it can run consistently across different environments.
On a Raspberry Pi running Ubuntu, Docker is a perfect match. It gives you the flexibility to deploy apps and services quickly, experiment with self-hosting projects, or even run a small lab environment for learning DevOps concepts.
In this guide, we’ll go step by step through the official installation process of Docker (and Docker Compose) so you can start building your own containerized homelab.
Prerequisites
Before starting, make sure you have the following:
- Raspberry Pi 4 (minimum 2 GB RAM; 4–8 GB recommended)
- Ubuntu Server 22.04 LTS or 24.04 LTS (64-bit)
- A user with
sudoprivileges - Internet connection
- (Optional) SSH access to manage the Pi remotely
Installation steps
The installation process includes cleaning up old Docker packages, adding Docker’s official repository, installing the required packages, and configuring permissions for non-root users.
Uninstall old versions
If you already have older versions of Docker or similar container tools installed (like docker.io, docker-compose, or podman-docker), it’s best to remove them first to avoid conflicts:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; doneSet up Docker’s repository
Now we need to add Docker’s official repository, but first we’ll install the required certificates and GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.ascAdd the repository to Apt sources
With the key installed, we can now add Docker’s repository to the system’s APT sources and update the package list:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt updateInstall the Docker packages
Once the repository is ready, install Docker Engine, the CLI, the container runtime, and the Compose plugin:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginAllow non-root user to run Docker
By default, you need sudo to run Docker commands. To make things easier, you can add your user to the docker group:
sudo usermod -aG docker $USERFast guide
If you prefer a quick installation, Docker provides a one-liner script that automates most of the process. The --dry-run flag lets you test what will be installed without making changes yet:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-runConclusion
Your Raspberry Pi is now ready to run Docker and Compose. With this setup, you can host multiple services, experiment with containerized apps, or even try out microservices architectures. This is a solid, official foundation to start your homelab journey.