A Universal Guide to Installing Docker on Debian and Ubuntu Systems
Introduction
Installing Docker on Linux should be straightforward, but the official documentation often fragments the process into separate pages for Debian and Ubuntu. In reality, these operating systems belong to the same family, and their installation processes are nearly identical.
Whether you are running the latest Ubuntu 24.04 LTS, Debian 13 (Trixie), or a derivative distribution like Kali Linux, ParrotSec, or Linux Mint, the logic remains the same.
This guide provides a unified, "evergreen" method to install Docker Engine using the modern DEB822 source format. This approach is cleaner, safer, and future-proof for modern apt-based systems.
Step 1: Prepare the system
First, we need to ensure the package index is updated and install the necessary dependencies to allow apt to use repositories over HTTPS.
Update the package index and install dependencies:
xinit@localhost:~$ sudo apt update && sudo apt install -y ca-certificates curl
Step 2: Define your distribution base
This is the only step where you need to make a choice. Docker repositories are organized by the "upstream" distribution.
- Choose debian if you use: Debian, Kali Linux, ParrotSec, Raspbian.
- Choose ubuntu if you use: Ubuntu, Linux Mint, Pop!_OS, Zorin OS.
Export the variable to make subsequent commands universal for your session:
# Change 'debian' to 'ubuntu' if you are on an Ubuntu-based system
xinit@localhost:~$ export DOCKER_DISTRO="debian"
Step 3: Add Docker’s official GPG key
Now we will create a dedicated directory for the keyrings. Unlike the old method of putting keys in /etc/apt/trusted.gpg, putting them in a dedicated directory is safer.
Create the directory with the correct permissions:
xinit@localhost:~$ sudo install -m 0755 -d /etc/apt/keyrings
Download the official Docker GPG key. By using the $DOCKER_DISTRO variable, this command automatically fetches the correct key for your system:
xinit@localhost:~$ sudo curl -fsSL https://download.docker.com/linux/$DOCKER_DISTRO/gpg -o /etc/apt/keyrings/docker.asc
Ensure the GPG key file is readable by all users. This is necessary because the apt package manager runs as a non-privileged user (_apt) and requires read access to verify signatures:
xinit@localhost:~$ sudo chmod a+r /etc/apt/keyrings/docker.asc
Step 4: Configure the repository (DEB822 style)
We will add the repository using the modern DEB822 format. This is superior to the old one-line sources.list format because it is structured and easier to parse.
Note for Derivative Distros: The command below uses $(... echo ...) magic to automatically detect your release codename (like bookworm or noble). It is designed to work on both standard and derivative systems automatically.
Create the source file:
xinit@localhost:~$ sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/$DOCKER_DISTRO
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
Now, update the apt cache to recognize the new Docker repository:
xinit@localhost:~$ sudo apt update
Step 5: Install Docker engine
With the repository configured, installing the Docker packages is the same for all distributions.
Install the Docker engine, CLI, containerd, and plugins:
xinit@localhost:~$ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 6: Post-installation setup
By default, Docker requires root privileges (sudo). To run Docker commands as a regular user, you need to add your user to the docker group.
Add your current user to the docker group:
xinit@localhost:~$ sudo usermod -aG docker $USER
Activate the group changes immediately without logging out:
xinit@localhost:~$ newgrp docker
Step 7: Verify installation
Finally, let's verify that the Docker service is active and capable of running containers.
Check the system service status:
xinit@localhost:~$ sudo systemctl status docker
Run the classic "Hello World" container to ensure the daemon can pull and run images correctly:
xinit@localhost:~$ docker run hello-world
Conclusion
You now have a fully functional Docker installation configured with the modern DEB822 repository standard. This setup is robust and will receive updates directly from Docker's official repositories, ensuring you always have the latest patches and features regardless of whether you are running Debian, Ubuntu, or a security-focused distro like Kali.