Jun 21, 2024 13 min read

How to Install Docker CE on Debian 12

Install Docker CE on Debian 12 with our step-by-step tutorial. Docker CE is a platform for building, packaging, and distributing applications.

Install Docker CE on Debian 12
Install Docker CE on Debian 12
Table of Contents


Before we begin talking about how to install Docker CE on Debian 12, let's briefly understand – What is Docker CE?

Docker CE is an open-source containerization platform that allows developers to build, package, and distribute applications in a consistent and efficient manner. With Docker CE, you can encapsulate your code, libraries, and dependencies into a single container that can run on any system, regardless of its underlying infrastructure. Docker CE simplifies the deployment process, reduces configuration errors, and improves resource utilization.

By using the power of containerization, Docker CE empowers developers to create portable, scalable, and flexible applications that can be deployed seamlessly across different environments. Embrace Docker CE to streamline application development and accelerate deployment, saving both time and effort.

In this tutorial, you will install Docker CE on Debian 12. We will also address a few FAQs on how to install Docker CE on Debian 12.

Advantages of Docker CE

  1. Containerization: Docker CE allows applications to be packaged in lightweight, portable containers, ensuring consistency across different environments.
  2. Efficient Resource Utilization: With Docker CE, multiple containers can run on a single machine, optimizing resource allocation and scaling applications easily.
  3. Easy Deployment: Docker CE simplifies the deployment process, reducing configuration errors and providing a consistent environment for applications to run.
  4. Scalability: Docker CE enables applications to scale horizontally by easily spinning up or down containers, ensuring efficient utilization of resources.
  5. Portability: Docker CE containers can run on any system, making it convenient to move applications across different environments and infrastructure without compatibility issues.

Docker Pre-Installation Steps on Debian

Docker CE setup on a Debian system is simple but requires careful attention to detail. Prior to beginning the installation procedure, let's prepare the system for an error-free run.

Step 1: Remove Previous Docker Instances on Debian

You can skip this step if you already have Docker installed from the Debian repository in its default version.

First, in order to guarantee a conflict-free environment, we need to remove any previous Docker installations. Previous Docker versions might cause unexpected errors and cause interference with our upcoming installation. If there are any older Docker iterations installed, use the following command to remove them:

sudo apt remove docker docker-engine docker.io containerd runc

The apt package manager will return a message indicating that there are no older Docker instances to uninstall.

It's important to keep in mind that Docker images, containers, volumes, and networks—all of which are typically kept in /var/lib/docker/—do not automatically disappear when Docker is removed. Use these commands to make a fresh start and remove all Docker-related data:

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

You've eliminated any possible Docker residues that might have affected your installation procedure by doing this.

Step 2: Update Debian Packages Before Docker Installation

The next step is to make sure your Debian system is fully updated after removing older Docker versions. By ensuring that your system packages are up-to-date and promoting system stability, updating helps to reduce potential conflicts and vulnerabilities.

Use the following command to upgrade the installed packages and update the list of available packages:

sudo apt update && sudo apt upgrade

Using this command will update the available package list first (apt update), then upgrade any out-of-date packages (apt upgrade).

Import Docker CE APT Repository on Debian 12

It's necessary to set up your Debian system to access the Docker repository in order to install Docker CE. This entails importing the relevant GPG key and integrating the Docker repository into your system. By taking these precautions, you can reduce the possibility of unwanted changes while ensuring the legitimacy of the downloaded Docker packages.

Step 1: Install Initial Packages For Docker CE on Debian

The system might not have the packages required for this procedure at first. Let's install them to fix that. Use these commands to install the necessary packages:

sudo apt install ca-certificates curl gnupg lsb-release dirmngr software-properties-common apt-transport-https

Here, you're installing a number of tools required for this process, such as gnupg for key management, curl for data transfer, and ca-certificates for certificate verification, using the apt package manager.

Step 2: Add Docker CE GPG Key on Debian

Let's import the Docker GPG key after installing the necessary packages. Your system can check the integrity of packages downloaded from the Docker repository thanks to this key.

The GPG key can be downloaded and saved using the following commands:

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

The GPG key is obtained from the Docker repository using the curl command. It is subsequently transformed into the binary format required by apt using gpg --dearmor.

Step 3: Add Docker CE APT Repository on Debian

Now that you have the GPG key set up, import the Docker repository. The command to do that is as follows:

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

This command, which appears complicated, links the previously downloaded GPG key to the Docker repository and adds it to your system's source list. By using this link, you can ensure that the packages you downloaded from the Docker repository are legitimate and safe for your system.

Install Docker on Debian 12 via APT

The steps required to install Docker CE on your Debian system are described in this section. You will discover how to install Docker, update the repository information on your system, and confirm the installation by running a test Docker image. Additionally, a critical security procedure to guarantee the safe management of Docker containers and images is included in this section.

Step 1: Update Debian APT Cache After Docker CE Repository Import

It's beneficial to make sure your system's repository information is current before starting the Docker installation, especially with the recently added Docker repository. Run the following command to update the repository's information:

sudo apt update

The package lists on your machine are updated with the most recent versions of the packages and their dependencies when you run this command.

Step 2: Install Docker on Debian 12

You can now install Docker after updating the system's repository information. The following command installs Docker and adds a few more plugins to improve your Docker experience:

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

This command installs the industry-standard runtime containerd.io, the Docker Community Edition (docker-ce), the Docker command-line interface (docker-ce-cli), and two helpful Docker plugins for managing multi-container apps and creating images.

Step 3: Verify Docker CE Installation on Debian

Run a test Docker image to ensure that Docker was installed correctly after finishing the installation process.

sudo docker run hello-world

Using the hello-world image that it extracts from the Docker repository, this command builds a new container and launches it. It verifies that Docker is operating as intended by printing a welcome message when it is executed.

Step 4: Running Docker as a Non-Root User on Debian

Set Docker to run as a non-root user for security reasons. This procedure protects your system from potentially harmful changes that may occur accidentally or maliciously. A longer discussion of this will be in a later section.

Docker Troubleshooting Tip

If you run into any problems when working with Docker containers and images, a system reboot may help fix the problem (especially if it has to do with path generation). You can use the following command to restart your system:


Managing Docker via Systemd on Debian 12

We'll look at using systemd to control the Docker service in this segment. A key element of many Linux distributions, such as Debian, is systemd, which offers tools for managing system services and processes. In your Debian system, Docker installs a systemd unit. This offers a convenient way to control the Docker service.

Starting the Docker Service on Debian via systemd

On your Debian system, the Docker service needs to be running in order to use Docker. This is made possible by Systemd using the following command:

systemctl start docker.service

This command ensures that the Docker service is available after every startup by starting it and configuring it to launch automatically upon system boot.

Stop Docker Service on Debian via systemd

There are situations where you might want to terminate the Docker service. Systemd offers an easy-to-use command to achieve this:

systemctl stop docker.service

With this command, you can stop the Docker service and make sure it doesn't launch automatically the next time the system boots up.

Restart Docker Service on Debian via systemd

Restarting the Docker service can be useful occasionally, particularly when troubleshooting Docker-related issues. With this command, Systemd offers the ability to restart the Docker service:

systemctl restart docker.service

By using this command, you can apply the most recent configurations by stopping and restarting the Docker service.

Check Docker Service Status on Debian via systemd

The systemd command below can be used to determine whether the Docker service is running, stopped, or not.

systemctl status docker.service

This command retrieves and shows the Docker service's current state, giving information about how well it is running.

Enable Docker Service on Debian System Boot via systemd

The recommended way to enable the Docker service to launch automatically at system boot is through systemd:

systemctl enable docker.service

By modifying the Docker service settings, this command ensures that Docker functionalities are always available and start automatically each time the system boots up.

Disable Docker Service on System Boot via systemd

If you choose not to have the Docker service launch automatically when your computer boots, you can make this request using the following command in systemd:

systemctl disable docker.service

By changing the Docker service settings, you can stop it from starting up automatically when your computer boots up.

You can take full control over Docker's operational behavior by using systemd commands to manage the Docker service on your Debian system. We'll go into more detail about using Docker and handling Docker images and containers in the following sections.

Configure Docker on Debian 12

We go into the details of configuring Docker configurations in this guide section. This includes customizing the default logging driver to better fit your needs and managing Docker as a non-root user, which improves security.

Step 1: Run Docker as a Non-Root User

Although it is possible to run Docker as the root user, doing so is not advised due to possible security risks and unintentional changes to your Debian host system. To improve security, use a non-root user account to oversee Docker operations instead.

Use these commands to create a new user specifically for Docker management:

sudo useradd -m dockeruser
sudo usermod -aG docker dockeruser

By using these commands, a new user called "dockeruser" is created and added to the Docker group. The rights required to execute Docker commands are granted to a user by membership in the Docker group.

You can substitute your username for "dockeruser" if you want to add your current user to the Docker group. For example, the command for a user called "joshua" would be:

sudo usermod -aG docker joshua

To apply the changes, log out and back in after making these changes. It is occasionally necessary to restart the system in order for the changes to take effect.

Use the following command to verify that the user is authorized to run Docker commands:

docker ps

A list of active Docker containers should appear when the command is executed, indicating that the Docker installation was successful.

Step 2: Modify Default Docker Logging Driver on Debian

Events are automatically logged by Docker in JSON file format. However, you can alter the default logging driver to a different format or even set it up to forward logs to a remote log management system thanks to Docker's flexibility.

You must create a new file in the /etc/docker/ directory named daemon.json in order to change the default logging driver. Enter the following command in a text editor like nano:

sudo nano /etc/docker/daemon.json

Paste the following content into the file while it is open:

  "log-driver": "syslog",
  "log-opts": {
    "syslog-address": "tcp://logs.example.com:514",
    "syslog-facility": "daemon",
    "tag": "{{.Name}}"

In this configuration, Docker relays logs to a remote syslog server using the syslog driver. Enter the address of your syslog server in place of logs.example.com.

To apply the updated logging driver settings, use the following command to restart the Docker daemon after the configuration is complete:

sudo systemctl restart docker.service

Please keep in mind any changes you may have made to the daemon.json. For the changes to take effect, the json file requires a restart of the Docker daemon.

Docker Command Examples on Debian 12

In this section, we explore the use of Docker commands, which are essential for efficiently handling volumes, networks, images, and containers with docker. A powerful and adaptable toolset for streamlining and automating tasks in your Docker environment is offered by the docker command.

Fundamentals of Docker Commands on Debian

To become proficient with Docker, one must become acquainted with the Docker command line interface (CLI). A variety of commands that you will likely run into during your Docker journey are listed below:

  • docker run: Launches a new container from an image.
  • docker ps: Displays all currently running containers.
  • docker images: Lists all locally available images.
  • docker build: Constructs a new image from a Dockerfile.
  • docker stop: Halts a currently running container.
  • docker rm: Eliminates a container.
  • docker rmi: Deletes an image.
  • docker network: Administers Docker networks.
  • docker volume: Manages Docker volumes.

You can customize the behavior of each command to suit your needs by using its distinct set of options. Let's investigate each command and its corresponding settings.

The docker run Command

Using an image as its source, a new container is created using the docker run command. For instance, run the following command to launch a container from the Debian image and launch an interactive shell inside of it:

docker run -it debian:latest /bin/bash

The docker ps Command

The command docker ps is used to list every container that is running at the moment. It displays important details about every container, such as the ID, related image, and operating state. Enter to see a list of all containers that are currently in use:

docker ps

The docker images Command

Listing every Docker image that is locally available is the responsibility of the docker images command. It provides details about every image, such as the ID, related repository, and tag:

docker images

The docker build Command

A Dockerfile can be used to create a new Docker image using the docker build command. In essence, a Dockerfile is a script that contains building instructions for a Docker image. For instance, you would use the following command to create a new image called "myimage" using the Dockerfile located in the current directory:

docker build -t myimage:latest .

The docker stop Command

A running Docker container can be gracefully ended with the docker stop command. With its ID, you can use the desired container as a target. For instance, to terminate a container with the ID "abcdefg," use:

docker stop abcdefg

The docker rm Command

To remove a Docker container, use the docker rm command. Give the container ID of the container you want to delete, just like you would with the stop command. As an illustration:

docker rm abcdefg

The docker rmi Command

To get rid of Docker images, use the docker rmi command. Use its ID to locate the image that you wish to remove. As an illustration:

docker rmi 1234567

The docker network Command

A flexible tool for adding, removing, and listing Docker networks is the docker network command. For example, in order to establish a new network called "mynetwork," you would use:

docker network create mynetwork

The docker volume Command

Lastly, features for managing Docker volumes are provided by the docker volume command. To make a new volume called "myvolume," for example, you would use:

docker volume create myvolume

The functionality and lifespan of a Docker environment are greatly impacted by efficient management of Docker containers. Many important sub-commands for working with Docker containers are available via the docker command. The creation, use, modification, and deletion of containers are made easier by these sub-commands. Knowing these commands can significantly improve your Docker interaction, regardless of your level of experience with containerization as a developer.

Core Commands for Docker Container Management with Debian

To list every container that is currently running, your Docker toolkit must include the command docker ps. You can view every container that is currently in use, along with its associated image, status, and distinct container ID, by running this command.

docker ps

The docker stop command is utilized to end an active Docker container. The name or unique ID of the container you wish to stop is appended.

docker stop abcdefg

A Docker container can be removed using the docker rm command. Similar to docker stop, this command takes as an argument either the name or the unique ID of the container.

docker rm abcdefg

It's important to remember that any changes you make are lost when you delete a container. You must use the "docker commit" command to make a new image from the altered container in order to preserve changes.

Retaining Container Changes using docker commit

It may be necessary for you to modify a container while working with Docker containers and save these changes as a new image. The docker commit command can be used to do this.

Make the required changes inside this container and start a new one with a base image. As an example, think about launching a fresh container from the Debian image and launching a shell within it:

docker run -it --name mycontainer debian:latest /bin/bash

This new container allows you to do a variety of operations, like editing configuration files and adding new software. Once the changes you want to make are made, use the docker commit command to create a new image that contains these changes. Use the following command to create a new image called "myimage" that contains the modifications made to the "mycontainer" container:

docker commit mycontainer myimage:latest

You now have an image called "myimage" that includes the modifications you made to the "mycontainer" container. To create and run fresh containers with updated software or configurations, use this new image.

Recall that the docker commit command only stores changes made to the filesystem of the container; networking and storage changes are not preserved. Use additional Docker commands such as docker network and docker volume if maintaining changes to networking and storage is required.

FAQs to Install Docker CE on Debian 12

Are there any prerequisites for installing Docker CE on Debian 12? 

Yes, Docker CE requires a 64-bit version of Debian 12 and a compatible Linux kernel.

Can I install Docker CE using package managers like apt-get or aptitude? 

Yes, Docker CE can be installed using package managers. Refer to the official Docker documentation for the specific commands.

Do I need root or sudo privileges to install Docker CE on Debian 12? 

Yes, you will need root or sudo privileges to install and manage Docker CE.

How can I verify if Docker CE is successfully installed on Debian 12?

After installation, run the docker version command to check the Docker client and server versions.

Can I use Docker CE on multiple Debian 12 machines with a single installation? 

Yes, Docker CE installations can be shared among multiple Debian 12 machines to manage and deploy containers.

Does Docker CE automatically start on system boot in Debian 12? 

Yes, Docker CE can be configured to start automatically on system boot by enabling the Docker service.

How do I update Docker CE to the latest version on Debian 12? 

Docker CE can be easily updated using the package manager. Check the Docker documentation for the required commands.


We hope this tutorial helped you understand how to install Docker CE on Debian 12.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.