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
dockergroup 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
