This guide provides step-by-step instructions for installing Docker Engine on a Debian-based system using Docker's official repository. This is the recommended method as it ensures you get the latest and most stable version.
First, remove any conflicting packages that might be installed from the default Debian repository.
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get autoremove
Next, configure your system to download packages from the official Docker repository instead of the default Debian repository.
sudo apt-get update
sudo apt-get install ca-certificates curl
This step ensures that the packages you download are authentic.
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
This command automatically detects your Debian version and sets up the repository accordingly.
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Now you can install the latest version of Docker Engine and its related components.
sudo apt-get update
The docker-compose-plugin
package provides the docker compose
command.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Run the hello-world
image to confirm that Docker Engine is installed and running correctly.
sudo docker run hello-world
If the installation was successful, you will see a "Hello from Docker!" message in your terminal.
To avoid typing sudo
every time you run a Docker command, add your user to the docker
group.
docker
group (if it doesn't already exist):sudo groupadd docker
docker
group:sudo usermod -aG docker $USER
Important: You need to log out and log back in for this change to take effect. Alternatively, you can run newgrp docker
in your current terminal session to activate the new group membership.
After this, you can run Docker commands directly (e.g., docker ps
).