Docker makes it easy to run applications in isolated containers without worrying about system conflicts. On Ubuntu, Docker helps developers, testers, and sysadmins build, ship, and run software faster using the same environment everywhere.

This guide explains how to install Docker on Ubuntu, verify the setup, and use Docker with real examples.
Step 1: Update the Ubuntu System
Always update your system before installing new software.
sudo apt update
sudo apt upgrade -y
This step ensures Ubuntu pulls the latest package information and security fixes.
Step 2: Install Required Dependencies
Docker needs a few system packages to work with secure repositories.
sudo apt install -y ca-certificates curl gnupg lsb-release
These tools allow Ubuntu to download and verify Docker packages safely.
Step 3: Add Docker’s Official GPG Key
Docker signs its packages with a GPG key. Ubuntu uses this key to verify authenticity.
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
This step prevents tampered or untrusted packages from installing.
Step 4: Add the Docker Repository
Now tell Ubuntu where to download Docker from.
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
Update the package list again:
sudo apt update
Step 5: Install Docker Engine
Install Docker and its core components.
sudo apt install -y docker-ce docker-ce-cli containerd.io
Check whether Docker installed correctly:
docker --version
Ubuntu should display the Docker version without errors.
Step 6: Verify Docker Installation
Run Docker’s test container to confirm everything works.
sudo docker run hello-world
Docker downloads a test image and prints a success message. This output confirms that Docker can pull images and run containers.
Step 7: Run Docker Without sudo (Recommended)
Running Docker with sudo every time slows down workflows. Add your user to the Docker group.
sudo usermod -aG docker $USER
Log out and log back in, then test:
docker run hello-world
Docker should now run without sudo.
Step 8: Learn Essential Docker Commands
These commands form the base of daily Docker usage.
Check Docker service status
systemctl status docker
List running containers
docker ps
List all containers
docker ps -a
List available images
docker images
Stop a running container
docker stop container_id
Remove a container
docker rm container_id
Remove an image
docker rmi image_id
Step 9: Run a Real Example (Nginx Web Server)
Start a web server inside a container.
docker run -d -p 8080:80 nginx
Open your browser and visit:
http://localhost:8080
Ubuntu now serves a live Nginx page directly from a Docker container.
Common Docker Issues and Fixes
- Docker command not found: Install Docker again using the official repository.
- Permission denied error: Add your user to the Docker group and re-login.
- Port already in use: Change the port mapping:
docker run -d -p 8081:80 nginx
FAQs
How do I install Docker on Ubuntu?
You can install Docker on Ubuntu by adding Docker’s official repository, updating packages, and running sudo apt install docker-ce docker-ce-cli containerd.io.
What is the easiest way to install Docker on Ubuntu?
The easiest way to install Docker on Ubuntu is through Docker’s official APT repository instead of Ubuntu’s default package manager.
Can I install Docker on Ubuntu without sudo?
You must use sudo to install Docker on Ubuntu, but you can run Docker commands without sudo by adding your user to the Docker group.
Which Ubuntu versions support Docker installation?
Docker supports Ubuntu 20.04, 22.04, and newer LTS versions officially.
How do I verify Docker after installation on Ubuntu?
Run docker run hello-world after you install Docker on Ubuntu to confirm it works correctly.
Why is Docker not working after I install Docker on Ubuntu?
Docker may not work if the service is not running. Start it using sudo systemctl start docker and check status with systemctl status docker.
How do I update Docker after I install Docker on Ubuntu?
Update Docker on Ubuntu by running sudo apt update and sudo apt upgrade if you installed it from the official repository.
Docker on Ubuntu provides a clean, repeatable, and efficient way to run applications. Once installed, Docker removes setup friction and helps you focus on building and deploying software instead of fixing environment issues.
