Docker has revolutionized software development and deployment, providing a lightweight and efficient containerization solution.
In this article, we’ll walk you through the step-by-step process of installing Docker on Debian 12 (Bookworm), empowering you to take advantage of its powerful features.
However, if you decide to opt for Docker Desktop instead, an intuitive and powerful GUI application that makes it easier to create, manage, and deploy Docker containers on systems with desktop environments, we’ve got you covered.
Our detailed guide, “How to Install Docker Desktop on Debian 12 (Bookworm),” will help you set it up quickly.
Whether you’re a beginner or an experienced user, our easy-to-follow instructions will ensure a smooth installation. So, let’s dive in!
Installing Docker on Debian 12
There are several ways to install Docker on your Debian 12 system. It is available in the official Debian repositories, where it can be easily installed with a single APT command. However, one disadvantage of this approach is that the version available is not always the most recent.
For this reason, I will show you how to install Docker on Debian 12 from the official Docker repository. This approach guarantees you always get the latest up-to-date version and will automatically receive all future software updates as they become available. So, letโs get started.
Step 1: Install Prerequisites
First, run the two commands below to update the package index and install the prerequisite necessary to add and use a new HTTPS repository.
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg
Code language: Bash (bash)
Step 2: Add Dockerโs GPG Repo Key
Next, import the Docker GPG repository key to your Debian system. This security feature ensures that the software youโre installing is authentic.
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
Code language: Bash (bash)
Notice that the command produces no output.
Step 3: Add the Docker Repo to Debian 12
After importing the GPG keys, weโll add the official Docker repository to our Debian 12 system.ย The best part is that if a new version is released, the update package will be made available with the rest of your systemโs regular updates.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Code language: Bash (bash)
As with the previous command, its execution produces no output.
Next, refresh the package list.
sudo apt update
Code language: Bash (bash)
As you can see, our new Docker repository is now available and ready to be used.
Step 4: Install Docker on Debian 12 (Bookworm)
To install the latest up-to-date Docker release on Debian, run the below command.
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Code language: Bash (bash)
This installs the following Docker components:
- docker-ce: The Docker engine itself.
- docker-ce-cli: A command line tool that lets you talk to the Docker daemon.
- containerd.io: A container runtime that manages the containerโs lifecycle.
- docker-buildx-plugin: A CLI plugin that extends the Docker build with many new features.
Thatโs all! Docker should now be installed; the service should start and be enabled to start automatically on boot.
In addition, you can check the Docker service status using the following:
sudo systemctl is-active docker
Code language: Bash (bash)
Step 5: Verify the Docker Installation
Now letโs check if everything with our new Docker installation works properly. For this purpose, we will run a simple application called โhello-world.โ
sudo docker run hello-world
Code language: Bash (bash)
Congratulations! As we can see, everything works as expected!
Enabling Non-root Users to Run Docker Commands
So far, we have successfully installed Docker on your Debian 12 system.
However, only root and users with sudo privileges can execute Docker commands by default. In other words, if you attempt to run the docker
command without prefixing it with sudo
, youโll get an error message like this:
docker ps
Code language: Bash (bash)
So, to run Docker commands as a non-root user, you must add your user to the “docker” group. To do that, type in the following:
sudo usermod -aG docker ${USER}
Code language: Bash (bash)
In the above command, ${USER}
is an environment variable that holds your username. To apply for the new group membership, reboot your Debian system.
You can then execute Docker commands without prefixing them with sudo
.
Conclusion
Throughout this article, we have explored the step-by-step process of installing Docker on Debian 12 (Bookworm).
It is worth noting that Docker is continuously evolving, with new features, improvements, and updates being introduced regularly. As such, staying up to date with the latest releases and security patches is recommended to ensure a smooth and secure Docker experience.
To learn more about Docker, check out the official Docker documentation. Additionally, we recommend our detailed guide to expand your skills with Docker and learn how to run and manage multi-container applications using Docker Compose. Happy dockering!