Back to all guides
Server Administration

How to Install Docker & Docker Compose on Ubuntu

3 read2026-04-10

Docker lets you run applications in isolated containers. This guide installs the official, up-to-date Docker Engine, not the outdated docker.io snap package that ships with Ubuntu by default.

1. Remove Old Versions

bash
sudo apt remove docker docker-engine docker.io containerd runc -y 2>/dev/null

2. Add Docker's Official Repository

bash
sudo apt update
sudo apt install ca-certificates curl gnupg -y

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

3. Install Docker Engine & Compose

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

4. Verify Installation

bash
sudo docker run hello-world
docker compose version

5. Run Docker Without sudo (Optional)

bash
sudo usermod -aG docker $USER
# Log out and log back in for this to take effect

6. Your First docker-compose.yml

Create a simple example to test everything works:

bash
mkdir ~/myapp && cd ~/myapp
nano docker-compose.yml
yaml
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
    restart: unless-stopped
bash
docker compose up -d
# Visit http://YOUR_IP:8080, you should see the Nginx welcome page
KVM Linux VPS

Looking for the right Linux VPS?

Put your project into practice right away: Our KVM VPS provide full root access, lightning-fast NVMe storage, and reliable KVM isolation. Flexible prepaid billing with no subscription and personal Discord support.

Full Root Access (SSH)
Datacenter NVMe SSD
4+ Tbps DDoS Protection
100% Prepaid (No Subscription)