Guides / DevOps / How to install Docker on Ubuntu
DevOps · Guide

How to install Docker on Ubuntu

Install Docker Engine on Ubuntu from Docker’s official apt repository, then run a test container. Running Docker without sudo is optional.

opnF.shNov 24, 2026Updated Nov 27, 20266 min readubuntu install dockerdockerubuntu
On this page 6 sections ▾

TL;DR

  • Install Docker Engine and its Compose plugin using Docker’s own repository. This lets Ubuntu’s package manager install and update them.
  • sudo docker run hello-world is the test: if it prints "Hello from Docker!", the install worked.
  • Adding yourself to the docker group drops the need for sudo, but Docker says that group grants root-level access, so only add people you'd trust with root.
New to this?Ping explains the hardest part in plain words.

Docker Engine runs applications in containers, isolated environments that package software with its dependencies. In this guide, you’ll install Docker Engine through Ubuntu’s apt package manager and run a test container. You need a 64-bit Ubuntu computer or virtual machine, internet access and an account with sudo privileges. Supported releases are 26.10, 26.04 LTS, 24.04 LTS and 22.04 LTS.

#1. Remove old or unofficial Docker packages

Docker Engine includes its own container runtime. If you previously installed Docker or a conflicting runtime through Ubuntu’s packages, remove those packages first. Review apt’s proposed removals if the machine already runs containers. If apt reports that none of the packages are installed, continue to step 2.

remove conflicting packagesBASH
1sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)

#2. Add Docker's apt repository

Add Docker’s official apt repository so Ubuntu can find the installation packages and verify them using Docker’s signing key. The commands below install the key, register the repository and refresh apt’s package list.

ELI5: explain it simply
Ping explainsNo experience needed.
THE WORDS
Repository
An online shelf of software packages that apt can download and install from.
Signing key
A file that lets your computer check a package really came from Docker and wasn't tampered with.
apt update
Refreshes the list of what's available on every shelf apt knows about.
THE IDEA

Think of Ubuntu's app store as a shop that only stocks Ubuntu's own shelves. This step adds a Docker shelf to the shop, along with Docker's seal on every box. Your computer checks that seal before installing anything, so it can tell a genuine Docker package from a fake one.

set up the repositoryBASH
1sudo apt update
2sudo apt install ca-certificates curl
3sudo install -m 0755 -d /etc/apt/keyrings
4sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
5sudo chmod a+r /etc/apt/keyrings/docker.asc
6
7sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
8Types: deb
9URIs: https://download.docker.com/linux/ubuntu
10Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
11Components: stable
12Architectures: $(dpkg --print-architecture)
13Signed-By: /etc/apt/keyrings/docker.asc
14EOF
15
16sudo apt update
✓
Tip

The Suites line fills in your Ubuntu release's code name by itself, like noble for 24.04, so the same block works on every supported version.

#3. Install Docker Engine on Ubuntu

One command installs five pieces: the Docker Engine itself, the docker command, containerd (which actually runs containers), and the Buildx and Compose plugins for building images and running multi-container apps.

install the packagesBASH
1sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Docker normally starts automatically after installation. Check the Docker client and Compose plugin versions:

check installed versionsBASH
1docker --version
2docker compose version

Both version commands should succeed. The version numbers confirm that the client and plugin are installed. Next, check whether the Docker service is running:

  1. Check the engineRun sudo docker system info. If it cannot reach the engine, check sudo systemctl status docker before moving on.

Get opnF in your inbox

Tech news for IT professionals that actually teaches you something.

Our promise to you: we'll be conscious about email quality/frequency, and your address will never be shared/sold.

#4. Test it with hello-world

The command below downloads hello-world from Docker Hub, a public registry for container images. Docker uses the image to create and run a container that prints a test message.

run your first containerBASH
1sudo docker run hello-world

Look for “Hello from Docker!” in the output. This confirms the client could reach the engine, download an image and run a container.

#5. Optional: Run Docker without sudo

!
Warning

Members of the docker group can take full control of this machine. Only grant membership to someone you would trust with root access. You can keep using sudo docker and skip this step.

The commands below add your signed-in user to the Docker group and open a shell with the new membership. Afterwards, run docker ps to check access. An empty list is normal when no containers are running.

join the docker groupBASH
1sudo usermod -aG docker "$USER"
2newgrp docker
~
Where it breaks

If you later publish a container port with Docker, its network rules may allow traffic despite existing UFW firewall rules. Review Docker’s firewall guidance before exposing a service.

#Optional settings and maintenance

After installation, you can configure how Docker logs activity, check disk usage, remove unused objects and sign in to Docker Hub.

Turn on log rotation

Log rotation means starting a fresh log file once the current one reaches a set size and deleting the oldest, so logs can't grow forever. Docker doesn't do this out of the box: its default json-file driver keeps adding to each container's log file, and over time those files can grow until the disk runs out of space.

Edit /etc/docker/daemon.json with sudoedit /etc/docker/daemon.json. On a fresh install, save the JSON below. If the file already has settings, merge these keys into the existing JSON object and preserve the others. The example keeps up to three log files of 10 MB each per new container.

/etc/docker/daemon.jsonJSON
1{
2 "log-driver": "json-file",
3 "log-opts": {
4 "max-size": "10m",
5 "max-file": "3"
6 }
7}

Keep the values in quotes because Docker reads log options as strings. Containers created after the change inherit these limits. Existing containers keep their previous settings until recreated.

!
Warning

By default, restarting Docker stops running containers. Apply this on a fresh install or during a maintenance window.

Validate the configuration first. The second command restarts Docker only if validation succeeds.

apply logging settingsBASH
1sudo dockerd --validate --config-file=/etc/docker/daemon.json &&
2sudo systemctl restart docker

Check how much space Docker is using

To see how much space images, containers, volumes and build cache use, run this read-only command:

check disk usageBASH
1sudo docker system df

Remove unused containers and images

Run the cleanup below only when you are ready to delete all stopped containers, unused networks, dangling images and unused build cache. A dangling image has no tag and no container using it. Review stopped containers first with sudo docker ps -a. Files saved only inside a container disappear when it is deleted. Volumes are kept by default.

remove unused Docker objectsBASH
1sudo docker system prune

Sign in to Docker Hub

Docker Hub is the public registry from which Docker downloaded the hello-world image. Anonymous pulls are limited to 100 per six hours per public IPv4 address or IPv6 /64 subnet. A free account allows 200 pulls in that period. Sign in using the same account context that will run Docker: use the command below with sudo, or omit sudo if you completed step 5.

sign in to docker hubBASH
1sudo docker login

Do DevOps work hands-on

DevOps & Infrastructure in DevOps Pro is where you actually work with tools like this, step by step, with labs and quizzes in a simulated terminal.

Open ›

Once a single container runs, the next question is how to run many of them across several machines, which is what Docker Swarm vs Kubernetes covers.

Should I install docker.io or docker-ce on Ubuntu?
Install docker-ce from Docker's repository if you want Docker's official release, since docker.io is Ubuntu's own package and Docker's guide removes it before installing.
How do I check if Docker is installed on Ubuntu?
Run docker --version to check for the command-line client. To verify that the engine can actually run a container, use sudo docker run hello-world and look for “Hello from Docker!”.
Why do I get "permission denied" when I run docker?
Your current shell may lack permission to access Docker’s socket. Use sudo docker ps, or follow the optional group setup in step 5 if this account should have root-level Docker access.
Can I use these steps on Linux Mint?
They may work, but Docker doesn't officially support Ubuntu-based distributions like Linux Mint, so you're on your own if something breaks.
How do I update Docker on Ubuntu?
Run sudo apt update, then the same install command from step 3; that's the upgrade path Docker's docs give. Now that Docker's repository is set up, a regular sudo apt upgrade picks up new Docker versions too.

Get opnF in your inbox

Tech news for IT professionals that actually teaches you something.

Our promise to you: we'll be conscious about email quality/frequency, and your address will never be shared/sold.