How to Install Docker on Ubuntu: A Complete Step-by-Step Guide

Docker has become one of the most widely used tools in modern software development and server management. Whether you're running a home lab, managing a production server, or just learning containerization, getting Docker installed correctly on Ubuntu is a foundational skill — and the process is straightforward once you understand what's actually happening under the hood.

What Docker Is and Why the Install Method Matters

Docker is a platform that lets you run applications inside isolated containers. Each container packages the application code, runtime, libraries, and dependencies together — so it runs consistently regardless of the host environment.

On Ubuntu, there are a few different ways to install Docker, and they don't all produce the same result. Choosing the wrong method can leave you with an outdated version, missing features, or permission issues that create headaches later.

The Three Main Installation Methods on Ubuntu

1. Docker's Official Repository (Recommended for Most Users)

Installing directly from Docker's official APT repository gives you the most current stable release and access to the full Docker Engine. This is the method Docker themselves maintain.

Here's the full process:

Step 1 — Update your package index and install prerequisites:

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

Step 2 — Add Docker's official GPG key:

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

Step 3 — Set up the 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 

Step 4 — Install Docker Engine:

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

Step 5 — Verify the installation:

sudo docker run hello-world 

If you see a confirmation message, Docker is installed and working.

2. Ubuntu's Snap Package

Ubuntu's default software repositories include a Docker snap package. It's fast to install:

sudo snap install docker 

However, the snap version has known limitations — particularly around volume mounts, file permissions, and networking in some configurations. It's convenient for quick testing but may create friction for more complex use cases.

3. Ubuntu's Default APT Repository

Running sudo apt install docker.io installs a version of Docker maintained by Ubuntu's packaging team, not by Docker Inc. This version often lags significantly behind the current release and may lack newer features or security patches.

Post-Installation: Running Docker Without sudo 🔧

By default, Docker commands require sudo. If you're running Docker frequently, this becomes inconvenient. Adding your user to the docker group resolves this:

sudo usermod -aG docker $USER 

After running this, log out and back in (or run newgrp docker) for the change to take effect. Verify with:

docker run hello-world 

Important note: Users in the docker group have root-equivalent privileges through Docker itself. This is an acceptable trade-off on personal machines or dedicated servers, but worth understanding in shared or multi-user environments.

Key Variables That Affect Your Install Experience

Not every Ubuntu system behaves identically. Several factors shape how the installation goes and what you can do afterward:

VariableWhy It Matters
Ubuntu versionDocker officially supports specific LTS releases (20.04, 22.04, 24.04). Older or non-LTS versions may have compatibility gaps
CPU architectureamd64 (x86_64), arm64, and armhf each require the correct package variant — critical for Raspberry Pi or ARM-based cloud instances
Existing Docker installationsOld versions left from docker.io can conflict with the newer Docker Engine packages
User privilegesWhether you're the system owner or a non-sudo user changes what's accessible
Virtualization environmentRunning Ubuntu inside VMware, VirtualBox, WSL2, or a cloud VM introduces variables around nested virtualization and kernel module availability

Removing Old Docker Versions Before Installing

If Docker was previously installed through any method, cleaning it up first prevents conflicts:

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

This doesn't delete your existing images, containers, or volumes — those live in /var/lib/docker unless you explicitly remove them.

Checking Your Ubuntu Version and Architecture 🖥️

Before starting, confirm what you're working with:

lsb_release -a dpkg --print-architecture 

The lsb_release output tells you your Ubuntu codename (e.g., jammy for 22.04, focal for 20.04, noble for 24.04) — which feeds directly into the repository setup command above.

Docker Compose: Bundled vs. Standalone

With modern Docker installations via the official repository, Docker Compose V2 is included as a plugin and called with:

docker compose up 

Older standalone versions used docker-compose (with a hyphen). If scripts or documentation you're following use the hyphenated version, it's referencing the legacy standalone tool. The plugin version is the current standard.

What "Working Correctly" Actually Looks Like

After a successful install, you should be able to:

  • Run docker --version and see a current release number
  • Pull and run a test image with docker run hello-world
  • List running containers with docker ps
  • Use docker compose for multi-container setups

If any of these fail, the issue almost always traces back to one of the variables above — architecture mismatch, a conflicting old installation, or a permissions gap on the docker socket.


The actual installation is consistent across most Ubuntu setups, but what comes next — how Docker fits into your workflow, what you run inside it, and how you manage access and networking — depends entirely on what you're building and how your system is configured. 🐳