How to Install Docker on Ubuntu: Complete Step-by-Step Guide (2026)

June 18, 2026 4 min read 1 views

Docker has become one of the most important tools in modern software development and DevOps workflows. It allows developers to package applications and their dependencies into lightweight containers that run consistently across different environments.

Whether you're deploying web applications, microservices, databases, or development environments, Docker simplifies application deployment and management.

In this guide, you'll learn how to install Docker on Ubuntu, verify the installation, run your first container, and configure Docker for everyday use.


What is Docker?

Docker is an open-source platform that enables developers to build, ship, and run applications inside containers.

Unlike virtual machines, containers share the host operating system's kernel, making them lightweight, fast, and efficient.

Benefits of Docker

  • Faster application deployment
  • Consistent development environments
  • Reduced resource usage
  • Easy scalability
  • Simplified dependency management
  • Improved CI/CD workflows

Prerequisites

Before installing Docker, ensure you have:

  • Ubuntu 20.04, 22.04, or 24.04
  • A user account with sudo privileges
  • Internet connectivity
  • Updated system packages

Check your Ubuntu version:

lsb_release -a

Output:

Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release: 24.04
Codename: noble

Step 1: Update Your Ubuntu System

First, update existing packages.

sudo apt update
sudo apt upgrade -y

This ensures your system has the latest security patches and dependencies.


Step 2: Install Required Packages

Install prerequisite packages needed to access Docker repositories over HTTPS.

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

Step 3: Add Docker's Official GPG Key

Create the keyring directory:

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

Download Docker's official GPG key:

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

Set proper permissions:

sudo chmod a+r /etc/apt/keyrings/docker.gpg

Step 4: Add Docker Repository

Add Docker's official repository to your system.

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

Update package information:

sudo apt update

Step 5: Install Docker Engine

Install Docker Engine and related components:

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

This installs:

PackagePurpose
docker-ceDocker Engine
docker-ce-cliDocker Command Line
containerd.ioContainer Runtime
buildx-pluginAdvanced Build Features
compose-pluginDocker Compose Support

Step 6: Verify Docker Installation

Check Docker version:

docker --version

Example output:

Docker version 28.x.x

Verify Docker service status:

sudo systemctl status docker

You should see:

active (running)

Step 7: Run Your First Docker Container

Test Docker by running the official hello-world container.

sudo docker run hello-world

Expected output:

Hello from Docker!
This message shows that your installation appears to be working correctly.

Congratulations! Docker is now installed successfully.


Step 8: Allow Running Docker Without sudo

By default, Docker commands require sudo.

Add your user to the Docker group:

sudo usermod -aG docker $USER

Apply changes:

newgrp docker

Or log out and log back in.

Now test:

docker run hello-world

No sudo should be required.


Step 9: Enable Docker at Boot

Ensure Docker starts automatically after reboot.

sudo systemctl enable docker

Verify:

sudo systemctl is-enabled docker

Output:

enabled

Common Docker Commands

Check Running Containers

docker ps

View All Containers

docker ps -a

Download an Image

docker pull nginx

Run an Nginx Container

docker run -d -p 80:80 nginx

List Images

docker images

Stop a Container

docker stop CONTAINER_ID

Remove a Container

docker rm CONTAINER_ID

Remove an Image

docker rmi IMAGE_ID

Installing Docker Compose

Modern Docker installations include Compose automatically.

Verify installation:

docker compose version

Example output:

Docker Compose version v2.x.x

Create a Sample Docker Compose Project

Create a file:

nano docker-compose.yml

Add:

services:
  nginx:
    image: nginx
    ports:
      - "8080:80"

Start the service:

docker compose up -d

Visit:

http://YOUR_SERVER_IP:8080

You should see the Nginx welcome page.


Troubleshooting Common Docker Installation Issues

Docker Command Not Found

Verify installation:

which docker

If missing:

sudo apt install docker-ce

Permission Denied

Error:

permission denied while trying to connect to Docker daemon

Solution:

sudo usermod -aG docker $USER

Then log out and back in.


Docker Service Not Running

Start Docker manually:

sudo systemctl start docker

Enable auto-start:

sudo systemctl enable docker

Repository Errors

Refresh package information:

sudo apt update

Verify repository:

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

Security Best Practices

When running Docker in production:

Keep Docker Updated

sudo apt update
sudo apt upgrade

Use Official Images

Prefer images from:

  • Docker Hub Official Images
  • Verified Publishers

Limit Container Privileges

Avoid:

--privileged

unless absolutely necessary.

Regularly Remove Unused Resources

docker system prune

Conclusion

Docker is an essential tool for modern developers, DevOps engineers, and system administrators. Installing Docker on Ubuntu is straightforward when using Docker's official repository.

After installation, you can start deploying applications, running development environments, building CI/CD pipelines, and managing microservices efficiently.

By following the steps in this guide, you now have a fully functional Docker environment on Ubuntu, complete with Docker Engine, Docker Compose, and essential management commands.

Whether you're developing locally or managing production servers, Docker provides a reliable and scalable foundation for containerized applications.


FAQ

Is Docker free to use?

Yes. Docker Engine is open-source and free for personal and many commercial uses.

Which Ubuntu versions support Docker?

Docker officially supports Ubuntu 20.04 LTS, 22.04 LTS, and 24.04 LTS.

Do I need Docker Compose separately?

No. Modern Docker installations include Docker Compose as a plugin.

Can Docker run on Ubuntu Server?

Yes. Docker is commonly installed on Ubuntu Server for hosting applications and services.

How do I update Docker?

sudo apt update
sudo apt upgrade docker-ce docker-ce-cli containerd.io

This updates Docker to the latest version available in the repository.

πŸ“€ Share this article

Sign in to save

Comments (0)

No comments yet. Be the first!

Leave a Comment

Sign in to comment with your profile.

πŸ“¬ Weekly Newsletter

Stay ahead of the curve

Get the best programming tutorials, data analytics tips, and tool reviews delivered to your inbox every week.

No spam. Unsubscribe anytime.