Learn how to install Docker on Ubuntu 22.04, 20.04, or 18.04 with this complete guide. Covers Docker Engine, Docker CLI, Docker Compose, and secure setup using official repositories. Step-by-step commands and detailed instructions make it easy for beginners and developers to get started with containerized apps on Linux.
Docker is a platform that allows developers to build, test, and run applications inside isolated environments called containers. It’s fast, lightweight, and ideal for development, testing, and deployment.
In this guide, you’ll learn how to install Docker on an Ubuntu system step-by-step, with complete explanations for every command.
This guide supports: Ubuntu 22.04, 20.04, and 18.04.
Table of contents [Show]
Before installing anything, make sure your package list and installed packages are up to date.
sudo apt update
sudo apt upgrade -y
This ensures compatibility with the latest Docker version.
Install packages that let APT use repositories over HTTPS and help securely fetch Docker’s key.
sudo apt install ca-certificates curl gnupg lsb-release
ca-certificates
: Required for SSL communicationcurl
: For downloading files from the internetgnupg
: For verifying package authenticitylsb-release
: To identify your Ubuntu version dynamicallyDocker signs its packages. You need to add their GPG key to verify the authenticity of packages.
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 saves Docker’s GPG key in a secure format used by APT.
Now, add Docker’s official repository to your APT sources list:
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
This ensures your system installs Docker from Docker Inc., not the Ubuntu archive.
After adding the Docker repo, reload your package index:
sudo apt update
You should now see packages from download.docker.com
if you run:
apt-cache policy docker-ce
This command installs Docker, Docker CLI, container runtime, and Docker Compose plugin:
sudo apt install docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
docker-ce
: Community Edition (the actual Docker engine)docker-ce-cli
: Command-line interface to interact with Dockercontainerd.io
: Lightweight container runtimedocker-compose-plugin
: Native support for Compose v2Check that Docker is installed and working:
sudo docker --version
Now test Docker by running a container:
sudo docker run hello-world
This pulls and runs a test image from Docker Hub. If successful, you’ll see a confirmation message from Docker.
sudo
To avoid typing sudo
every time, add your user to the docker
group:
sudo usermod -aG docker $USER
Important: You must log out and log back in (or reboot) for changes to take effect.
After that, you can run:
docker ps
...without needing sudo
.
Ensure Docker starts automatically when the server reboots:
sudo systemctl enable docker
If you ever need to remove Docker:
sudo apt remove docker-ce docker-ce-cli containerd.io
To delete all data:
sudo rm -rf /var/lib/docker
Yes, it works perfectly for 22.04 and all recent LTS versions including 20.04 and 18.04.
The official Docker repository always provides the latest stable version with critical updates and bug fixes faster than the Ubuntu-maintained version.
sudo systemctl status docker
sudo systemctl stop docker
sudo systemctl start docker
sudo systemctl restart docker
docker ps
docker ps -a
You now have Docker fully installed and configured on Ubuntu. With Docker up and running, you can:
docker-compose
for multi-container appsIf you’re ready to take the next step, explore Docker Compose or Kubernetes integration.
Need help deploying real-world apps with Docker? Let me know and I’ll write tutorials for WordPress, Node.js, and more!
Your email address will not be published. Required fields are marked *