How to Install Docker Engine on Ubuntu & Debian (Complete Guide)

Docker lets you package applications and their dependencies into lightweight, isolated containers that run consistently across any server. This guide installs Docker Engine from Docker's official repository — the recommended method, ensuring you always get current, supported releases — on both Ubuntu (22.04/24.04) and Debian (11/12).

Prerequisites

  • Ubuntu 22.04/24.04 or Debian 11/12 VPS
  • Root or sudo access
  • Internet connectivity

Step 1 — Update the System

sudo apt update
sudo apt upgrade -y

Step 2 — Install Required Packages

sudo apt install ca-certificates curl gnupg -y

Step 3 — Add Docker's Official GPG Key

sudo install -m 0755 -d /etc/apt/keyrings

On Ubuntu:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

On Debian:

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Step 4 — Add the Docker Repository

On Ubuntu:

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

On Debian, replace ubuntu with debian in the URL:

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

Step 5 — Install Docker Engine

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

This single command installs Docker Engine, the CLI, containerd, Buildx, and the Compose V2 plugin together.

Step 6 — Verify the Installation

docker --version
docker compose version

Step 7 — Enable Docker at Boot

sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl status docker

Step 8 — Run a Test Container

sudo docker run hello-world

If successful, Docker downloads a small test image and prints a confirmation message.

Step 9 — Run Docker Without sudo (Optional)

sudo usermod -aG docker $USER
newgrp docker

Log out and back in for group changes to fully apply. Note this grants the user effective root-equivalent access to the host — only add trusted accounts to the docker group.

Common Errors

"Cannot connect to the Docker daemon" — the service isn't running:

sudo systemctl restart docker

Permission denied — either use sudo or add your user to the docker group as shown above.

Repository 404 / GPG errors — confirm you used the correct distribution (ubuntu vs debian) in the repository URL and that $VERSION_CODENAME matches a supported release.

Best Practices

  • Always install from Docker's official repository, not the distro's default (often outdated) package
  • Keep Docker updated (see How to Update Docker and Docker Compose Safely)
  • Restrict the docker group to trusted users only

FAQ

Is Docker free?
Yes, Docker Engine (Community Edition) is free and open source.

Do I need to install Docker Compose separately?
No — the docker-compose-plugin package installs it as an integrated docker compose subcommand.

Related Articles

  • How to Install Docker Compose on Ubuntu & Debian
  • Deploy Your First Docker Container
  • Docker Security Best Practices
  • docker, install docker, docker engine, ubuntu docker, debian docker
  • 0 gebruikers vonden dit artikel nuttig
Was dit antwoord nuttig?

Gerelateerde artikelen

How to Install Docker Compose on Ubuntu & Debian

Docker Compose lets you define and run multi-container applications from a single YAML file,...

Deploy Your First Docker Container: A Beginner's Walkthrough

With Docker installed, this hands-on walkthrough covers the core workflow you'll use constantly:...

How to Update Docker and Docker Compose Safely

Keeping Docker Engine and Compose updated brings security fixes, performance improvements, and...

Docker Compose Troubleshooting: Common Errors & Fixes

A reference guide to the Docker and Docker Compose errors you're most likely to encounter, with...

How to Install Portainer for Web-Based Docker Management

Portainer provides a graphical web dashboard for managing Docker containers, images, networks,...