How to Install Docker on Debian 12 (Bookworm)

Learn step-by-step how to install Docker on Debian 12 and unlock the power of containerization. Get started with our comprehensive guide.

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 gnupgCode 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.gpgCode language: Bash (bash)
Add Dockerโ€™s repo GPG key.
Add Dockerโ€™s GPG repo key.

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/nullCode language: Bash (bash)
Add the official Docker repository to Debian 12.
Add the official Docker repository to Debian 12.

As with the previous command, its execution produces no output.

Next, refresh the package list.

sudo apt updateCode language: Bash (bash)
Update the package base.
Update the package base.

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-pluginCode language: Bash (bash)
Install Docker on Debian 12 (Bookworm).
Install Docker on Debian 12 (Bookworm).

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 dockerCode language: Bash (bash)
Check the status of the Docker service.
Check the status of the Docker service.

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-worldCode language: Bash (bash)
Docker successfully installed, up & running on Debian 12.
Docker successfully installed, up & running on Debian 12.

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 psCode language: Bash (bash)
Docker permission denied.
Docker permission denied.

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.

Run the docker command as a regular user.
Run the docker command as a regular user.

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!

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 68%