How to Install Docker on Ubuntu
A step-by-step tutorial to install Docker Engine and Docker Compose on Ubuntu Server, then run your first container.
This tutorial installs the official Docker Engine and Compose plugin on Ubuntu, then verifies everything with a test container. It takes about ten minutes.
Prerequisites
- Ubuntu Server 22.04 or newer
- A user with
sudoaccess
Step 1: Remove old versions
sudo apt remove docker docker-engine docker.io containerd runcStep 2: Add Docker's official repository
sudo apt update
sudo apt install ca-certificates curl gnupg
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
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullStep 3: Install Docker Engine and Compose
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-pluginStep 4: Run Docker without sudo
sudo usermod -aG docker $USER
newgrp dockerLog out and back in for the group change to fully apply.
Step 5: Verify the installation
docker run hello-world
docker compose versionIf you see the "Hello from Docker!" message, you're ready.
Step 6: Your first real container
mkdir -p ~/whoami && cd ~/whoami
cat > compose.yaml <<'EOF'
services:
whoami:
image: traefik/whoami
ports:
- "8088:80"
restart: unless-stopped
EOF
docker compose up -dVisit http://your-server-ip:8088 to see it respond.
Next steps
- Learn the fundamentals in Docker basics.
- Deploy Pi-hole or Jellyfin.
- Keep images updated:
docker compose pull && docker compose up -d.
You now have a container platform ready for dozens of self-hosted apps.
Related articles
Docker Basics for Self-Hosting
Learn images, containers, volumes and Docker Compose so you can deploy self-hosted applications with confidence.
The Complete Home Server Beginner's Guide
Go from zero to a running home server: choose hardware, pick an operating system, deploy your first apps, and keep everything secure and backed up.
How to Set Up Pi-hole for Network-Wide Ad Blocking
Install Pi-hole with Docker to block ads and trackers for every device on your home network.