Debian

How to Install Docker CE on Debian 12

Docker is a containerization platform. It allows the developers to package the applications along with the necessary dependencies into the lightweight, isolated containers. This method ensures consistency and portability across different environments. Docker’s efficient containerization minimizes the overhead of virtualization, making it ideal for deploying the applications from the local development environments to the cloud infrastructures. With Docker, the developers can easily share, distribute, and scale the applications. This streamlines the development process and promotes DevOps practices. Its vast ecosystem of pre-built images and Docker Hub repository facilitates rapid application deployment and fosters collaboration among developers. This makes Docker an essential tool in the modern software development.

In this article, we will show you how to install the latest version of Docker CE on Debian 12 “Bookworm”.

Topic of Contents:

    1. Updating the Debian 12 Package Database Cache
    2. Removing the Conflicting Docker Packages from Debian 12
    3. Installing the Prerequisite Packages on Debian 12
    4. Installing the GPG Key of the Official Docker Repository on Debian 12
    5. Adding the Official Docker Package Repository on Debian 12
    6. Installing Docker CE on Debian 12
    7. Adding a Debian 12 Login User to the Docker Group
    8. Checking If Docker and Docker Compose Are Accessible on Debian 12
    9. Conclusion

Updating the Debian 12 Package Database Cache

To update the Debian 12 package database cache, run the following command:

$ sudo apt update

 

Removing the Conflicting Docker Packages from Debian 12

If you installed Docker from the official Debian 12 package repository already, you must uninstall/remove them before installing the Docker from the official Docker package repository. This is to make sure that the Debian-packaged version of Docker does not conflict with the official Docker-packaged version of Docker.

To remove the conflicting Docker packages from Debian 12, run the following command:

$ sudo apt remove --purge docker.io docker-doc docker-compose podman-docker containerd runc

 
In our case, no conflicting Docker packages are installed. If you have any, it will be removed.

Installing the Prerequisite Packages on Debian 12

To install the official Docker package repository on Debian 12, you need to install some packages on your Debian 12.

You can install the required packages with the following command:

$ sudo apt install ca-certificates curl gnupg

 
To confirm the installation, press Y and then press <Enter>.


The required packages should be installed.

Installing the GPG Key of the Official Docker Repository on Debian 12

Before you can add the official Docker package repository to your Debian 12 system, you must install the GPG key of the official Docker repository on your Debian 12 system.

To make sure that the /etc/apt/keyrings directory has the correct access permissions, run the following command:

$ sudo install -m 0755 -d /etc/apt/keyrings

 
To download the GPG key of the official Docker package repository and save it in the /etc/apt/keyrings directory of your Debian 12 system, run the following command:

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

 
To make sure that everyone can read the GPG key file of the official Docker package repository, run the following command:

$ sudo chmod a+r /etc/apt/keyrings/docker.gpg

 

Adding the Official Docker Package Repository on Debian 12

To add the official Docker package repository on your Debian 12 system, run the following command:

$ echo  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" |  sudo tee /etc/apt/sources.list.d/docker.list

 
For the changes to take effect, make sure to update the Debian 12 package database cache with the following command:

$ sudo apt update

 

Installing Docker CE on Debian 12

To install the latest version of Docker CE on Debian 12, run the following command:

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

 
To confirm the installation, press Y and then press <Enter>.


Docker CE and the required dependency packages are being downloaded from the internet. It takes a while to complete.


Docker CE and the required dependency packages are being installed. It takes a while to complete.


At this point, the latest version of Docker CE should be installed on your Debian 12 machine.

Adding a Debian 12 Login User to the Docker Group

To run the Docker commands without superuser privileges, you must add the login user of your Debian 12 system to the Docker group.

To add the login user of your Debian 12 system to the Docker group, run the following command:

$ sudo usermod -aG docker $(whoami)

 
For the changes to take effect, reboot your Debian 12 system with the following command:

$ reboot

 

Checking If Docker and Docker Compose Are Accessible on Debian 12

Once your computer boots, run the following commands from a Terminal app to check whether you can access Docker:

$ docker version

 
If Docker is accessible, the installed Docker version number and build information should be printed. As you can see, Docker version 24.0.4 is installed on our Debian 12 system.


To check whether you can access the Docker Compose, run the following command:

$ docker compose version

 
If Docker Compose is accessible, the installed Docker Compose version number should be printed. As you can see, the Docker Compose version 2.19.1 is installed on our Debian 12 system.

Conclusion

We showed you how to install the latest version of Docker Community Edition (CE) and Docker Compose on Debian 12 “Bookworm”. We also showed you how to run the Docker on Debian 12 without superuser (root) privileges and how to check if Docker and Docker Compose are accessible on Debian 12 as well.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.