How to Install Docker on Ubuntu (Quick Setup)
In this tutorial, you'll learn about How to Install Docker on Ubuntu (Quick Setup). We cover key concepts, practical examples, and best practices.
The Problem
You want Docker on Ubuntu. The default apt package is outdated — use Docker's official repo instead.
Why not use the Ubuntu repository
Ubuntu's docker.io package is often months or years behind the official release, missing security patches and new features. Docker's official repository provides the latest stable versions within hours of each release.
What you are installing
Docker Engine is the core runtime. docker-ce-cli is the command-line tool. containerd.io is the underlying container runtime. docker-buildx-plugin adds multi-platform builds. docker-compose-plugin enables multi-container applications with <a href="/devops/docker-compose/">docker compose</a>.
Quick Fix
1. Uninstall old versions
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt remove $pkg; done
This removes any pre-existing Docker-related packages. The $pkg variable iterates through the list, and sudo apt remove uninstalls each one. If a package is not installed, apt shows a warning but continues. It is safe to run this even if you have never installed Docker before — it just confirms that no conflicting packages exist.
2. Set up Docker's apt repository
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
This sequence downloads and installs Docker's GPG key (so apt can verify package signatures), creates a new apt source file pointing to Docker's repository, and updates the package index. The $(dpkg --print-architecture) automatically detects your CPU architecture (usually amd64 or arm64), and $(. /etc/os-release && echo "$VERSION_CODENAME") detects your Ubuntu release codename (like noble for 24.04). This ensures you get the correct packages for your specific system.
3. Install Docker
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
This single command installs all the Docker components: the daemon, the command-line client, the container runtime, and the plugins. Unlike the docker.io package from Ubuntu's repos, these packages are the official releases maintained by Docker Inc.
4. Verify
sudo docker run hello-world
Expected output:
Hello from Docker!
This message shows that your installation appears to be working correctly.
The hello-world image is a tiny test container that prints this message and exits. If you see this output, Docker Engine is installed, the daemon is running, and it can pull images from Docker Hub. If you get "Cannot connect to the Docker daemon," the Docker service may not be running — try sudo systemctl start docker.
5. Run Docker without sudo (optional)
sudo usermod -aG docker $USER
# Log out and back in
Adding your user to the docker group gives you permission to run Docker commands without sudo. The -aG flag appends the group without removing existing groups. You must log out and back in for the group change to take effect. If you do not want to log out, run newgrp docker to start a new shell session with the updated group.
Test Docker Compose
docker compose version
If Docker Compose is installed correctly, this shows the version number (for example, <a href="/devops/docker-compose/">Docker Compose</a> version v2.29.0). You can now create a compose.yml file in your project and run <a href="/devops/docker-compose/">docker compose</a> up to start multi-container applications with a single command.
Prevention
Do not use sudo apt install docker.io. The Ubuntu repo version is almost always outdated. Verify your source with apt-cache policy docker-ce.
Add your user to the docker group after installation. Running Docker with sudo for every command is tedious and can cause permission issues with mounted volumes.
Keep Docker updated. Run sudo apt update && sudo apt upgrade regularly. Subscribe to Docker's security advisory feed for critical updates.
Monitor disk usage. Docker images consume significant space. Run docker system prune periodically to remove unused images, containers, and networks.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro