Skip to content
ContainersBeginner

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.

by HomeServersGuide Team1 min read

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 sudo access

Step 1: Remove old versions

sudo apt remove docker docker-engine docker.io containerd runc

Step 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/null

Step 3: Install Docker Engine and Compose

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

Step 4: Run Docker without sudo

sudo usermod -aG docker $USER
newgrp docker

Log out and back in for the group change to fully apply.

Step 5: Verify the installation

docker run hello-world
docker compose version

If 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 -d

Visit http://your-server-ip:8088 to see it respond.

Next steps

You now have a container platform ready for dozens of self-hosted apps.

Related articles

ContainersBeginner

Docker Basics for Self-Hosting

Learn images, containers, volumes and Docker Compose so you can deploy self-hosted applications with confidence.

1 min read
Getting StartedBeginner

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.

2 min read
NetworkingBeginner

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.

1 min read