How to Install Docker on Ubuntu (20.04, 22.04 & 24.04)

Overview

Docker is a containerisation platform that lets you package and run applications in isolated environments called containers. Instead of installing software directly on your server and wrestling with dependency conflicts, you spin up a container, run your app, and tear it down when you’re done. It’s become standard on everything from developer laptops to production VPS SSD Hosting environments.

The Docker installation process on Ubuntu is well-documented but easy to get wrong. The main mistake I see is people installing the docker.io package from Ubuntu’s default repositories. That version is almost always outdated. This guide uses Docker’s official APT repository, which is the right way to do it.

This article covers Ubuntu 20.04 (Focal), 22.04 (Jammy), and 24.04 (Noble). The steps are nearly identical across all three, but I’ll call out any differences where they exist.

Prerequisites

  • A server or VPS running Ubuntu 20.04, 22.04, or 24.04 (64-bit)
  • Root or sudo access
  • At least 2 GB of RAM recommended for running containers comfortably
  • A working internet connection from the server (Docker pulls images from Docker Hub)
  • Basic familiarity with the Linux command line

Step-by-Step Installation

Step 1: Remove Old or Conflicting Docker Packages

Before installing anything, remove any existing Docker packages that might conflict. Ubuntu’s default repos ship packages named docker.io, docker-compose, and a few others that will clash with the official Docker packages.

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

If none of those are installed, apt will just say so and move on. That’s fine.

Step 2: Update Your Package Index and Install Dependencies

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

These packages let your system verify the Docker repository’s GPG key and handle HTTPS transport for APT.

Step 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

The chmod a+r at the end ensures APT can actually read the key file. Skipping this causes a silent failure that’s annoying to debug.

Step 4: Add the Docker APT Repository

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

This uses VERSION_CODENAME from /etc/os-release to automatically pick the right repo for your Ubuntu version — whether that’s focal, jammy, or noble.

📝 Note: If you’re on Ubuntu 24.04 and hit an error here, double-check that /etc/os-release contains VERSION_CODENAME=noble. Some minimal cloud images occasionally omit this line.

Step 5: Install Docker Engine

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

This installs Docker Engine (docker-ce), the CLI, containerd as the container runtime, and the Buildx and Compose plugins. You want all of these. Running just docker-ce alone will leave you missing docker compose (v2) later.

Step 6: Verify the Installation

sudo docker run hello-world

Docker will pull the hello-world image from Docker Hub and run it. If you see “Hello from Docker!” in the output, the installation is working correctly.

Step 7: Enable Docker to Start on Boot

sudo systemctl enable docker
sudo systemctl start docker

On most Ubuntu cloud images, Docker starts automatically after install. Still worth confirming, especially on VPS environments where some providers ship stripped-down systemd configurations.

Step 8: Add Your User to the Docker Group (Post-Install)

By default, running Docker commands requires sudo. If you’re managing your own server and don’t want to prefix every command, add your user to the docker group.

sudo usermod -aG docker $USER
newgrp docker

⚠ Warning: Adding a user to the docker group is effectively giving them root-equivalent access on that machine. The Docker daemon runs as root and a user in the docker group can mount the host filesystem into a container. Only do this on servers where you trust all users with sudo-level access.

After running newgrp docker, test without sudo:

docker ps

If you still get a permission error, log out and back in. The group change doesn’t always apply immediately in all terminal sessions.

Verify Docker Compose v2

The old docker-compose (v1, standalone Python binary) is deprecated. The current version ships as a Docker CLI plugin and is called with docker compose (no hyphen).

docker compose version

You should see something like Docker Compose version v2.27.x or newer. If the command isn’t found, go back and make sure you installed docker-compose-plugin in Step 5.

Common Issues & Troubleshooting

Permission denied while connecting to the Docker daemon socket

Cause: You’re running docker commands as a non-root user who isn’t in the docker group, or the group change hasn’t taken effect in the current session.

Fix: Either prefix your command with sudo, or run newgrp docker after adding yourself to the group. If that doesn’t work, fully log out and back in. SSH sessions don’t always pick up group changes until the session is refreshed.

Cannot connect to the Docker daemon — is it running?

Cause: The Docker service isn’t started, or it failed to start due to a port or socket conflict.

Fix: Check the service status and logs:

sudo systemctl status docker
sudo journalctl -u docker --no-pager -n 50

A common culprit on VPS hosts is an existing containerd installation conflicting with the one Docker tries to manage. Removing the system containerd package and letting Docker manage its own usually resolves it.

Package docker-ce has no installation candidate

Cause: The Docker APT repository wasn’t added correctly, or apt update wasn’t run after adding it.

Fix: Verify the repo file exists and looks correct, then refresh:

cat /etc/apt/sources.list.d/docker.list
sudo apt update

If the file is empty or missing, repeat Steps 3 and 4. A wrong codename in the repo URL (e.g. accidentally using focal on a 22.04 system) will also cause this error.

docker: Error response from daemon: pull access denied

Cause: The image name is wrong, the image is private and you’re not authenticated, or Docker Hub rate limiting has kicked in on an unauthenticated IP.

Fix: Double-check the image name and tag. For private images, run docker login first. For rate limiting, logging in with a free Docker Hub account significantly raises your pull limits. This error is annoyingly common on shared NAT VPS environments where many servers share an outbound IP.

Failed to set up loop device / overlayfs errors on older kernels

Cause: Docker’s default storage driver is overlay2, which requires a kernel version of at least 4.0 with overlay support compiled in. Some older Ubuntu 20.04 LTS installs on certain VPS providers ship with kernels that lack this.

Fix: Check your kernel version with uname -r. If you’re on a kernel older than 5.4, I’d recommend upgrading via sudo apt install linux-generic and rebooting. Running Ubuntu 22.04 or 24.04 avoids this entirely.

FAQ

Frequently Asked Questions

Can I install Docker on a shared hosting plan?

No. Docker requires root access and kernel-level features that shared hosting environments don’t provide. You’ll need a VPS or dedicated server to run Docker. Host & Tech’s VPS plans start at $5.83/mo and give you full root access out of the box.

What's the difference between docker-ce and docker.io?

docker-ce is Docker’s official Community Edition, distributed directly by Docker Inc through their own APT repository. docker.io is Ubuntu’s repackaged version, which tends to lag several major versions behind. For anything beyond testing, always install docker-ce from Docker’s official repo.

How do I update Docker after installation?

Since you installed Docker through APT, updating is just a standard package upgrade: run sudo apt update && sudo apt upgrade docker-ce docker-ce-cli containerd.io. You don’t need to uninstall and reinstall. Check the current version with docker version.

Does Docker work on Ubuntu running inside a VPS or VM?

Yes, in most cases. Most modern hypervisors (KVM, Xen, VMware) support the kernel features Docker needs. OpenVZ-based VPS containers are the main exception — they use container-level virtualisation that can block Docker from running properly. If you’re on a Host & Tech KVM VPS, Docker works without any special configuration.

How do I completely uninstall Docker from Ubuntu?

Run sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin to remove all packages. Docker doesn’t automatically delete images, containers, or volumes when you uninstall — those live in /var/lib/docker. Remove that directory manually with sudo rm -rf /var/lib/docker if you want a clean slate.

SHARE THIS ARTICLE

Need help with your hosting?

Host & Tech provides 24/7 support for all VPS, dedicated, and shared hosting customers.

Scroll to Top