Install Docker on Ubuntu/Debian

Official Docker CE installation with Compose Plugin and service verification.

Back to Guides ยท Home

Applies to: Ubuntu 20.04/22.04/24.04, Debian 11/12

Installs: Docker CE, Docker CLI, containerd, Compose Plugin

1. Remove Old Docker Versions (if any)

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

2. Install Prerequisites

sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release

3. Add Docker's Official GPG Key

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

4. Set Up the Docker Repository

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5. Install Docker CE and Components

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

6. Start and Enable Docker

sudo systemctl enable --now docker
sudo systemctl status docker --no-pager
docker --version
docker compose version

7. (Optional) Allow Non-root Docker Access

sudo usermod -aG docker $USER
newgrp docker
# Log out and back in for changes to take effect

8. Verify Installation

docker run --rm hello-world

If you see "Hello from Docker!", installation was successful.

9. Common Maintenance Commands

sudo systemctl restart docker
sudo systemctl stop docker
sudo systemctl start docker
sudo journalctl -u docker --no-pager | tail -n 50