How to Install Docker CE on Debian 12, 11, or 10

Docker Community Edition (Docker CE) is a pivotal tool in application development, offering a free platform for creating, delivering, and running applications via containers. If you’re planning on learning to install Docker CE on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster, this introduction will provide a concise overview of its key features and benefits:

  • Versatility and Consistency: Docker CE ensures applications run consistently across various computing environments, from local machines to cloud-based systems.
  • CI/CD Pipeline: It supports a smooth development, testing, and deployment pipeline, allowing for rapid iteration and minimizing compatibility issues.
  • Isolation and Security: With each container running independently, Docker CE prevents system-wide failures and enhances security by isolating resources and reducing potential attack surfaces.

Mastering Docker CE’s fundamental concepts include images, containers, and Dockerfiles. With these basics, you’ll be well-equipped to leverage Docker’s capabilities to enhance your development workflow significantly. The following guide will walk you through the installation process of Docker CE on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster, providing detailed steps to efficiently get Docker CE up and running on your Debian system.

Docker Pre-Installation Steps on Debian

Setting up Docker CE on your Debian system is straightforward yet meticulous. Before delving into the installation process, let’s set the stage for an error-free execution.

Step 1: Remove Previous Docker Instances on Debian

If you do not have the default version of Docker installed from Debian’s repository, skip the removal step.

First, we must purge any pre-existing Docker installations to ensure a conflict-free environment. Prior Docker versions could interfere with our upcoming installation and lead to unexpected errors. Use the following command to uninstall older Docker iterations if they exist:

sudo apt remove docker docker-engine containerd runc

Should there be no older Docker instances to remove, the apt package manager will return a message indicating nothing to uninstall.

It’s crucial to remember that uninstalling Docker does not automatically delete Docker images, containers, volumes, or networks that are usually stored in /var/lib/docker/. If you intend to start afresh and eliminate all Docker-related data, use these commands:

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

With this, you’ve purged any potential Docker residues that could influence your installation process.

Step 2: Update Debian Packages Before Docker Installation

After removing older Docker versions, ensure your Debian system is fully updated as your next step. Updating promotes system stability and ensures your system packages are at their latest versions, minimizing potential conflicts and vulnerabilities.

To update the list of available packages and upgrade the installed ones, run the following command:

sudo apt update && sudo apt upgrade

This command will first refresh the list of available packages (apt update), followed by the upgrade of any outdated packages (apt upgrade).

Import Docker CE APT Repository on Debian 12, 11, or 10

To successfully install Docker CE, it’s essential to configure your Debian system to access the Docker repository. This involves integrating the Docker repository into your system and importing the corresponding GPG key. These steps ensure the authenticity of the downloaded Docker packages and mitigate the risk of unauthorized alterations.

Step 1: Install Initial Packages For Docker CE on Debian

Initially, the system may lack the necessary packages for this process. Let’s rectify that by installing them. Execute the following command to install these critical packages:

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

Here, you’re leveraging the apt package manager to install a variety of tools, like ca-certificates for certificate verification, curl to transfer data, gnupg for key management, and others necessary for this process.

Step 2: Add Docker CE GPG Key on Debian

After installing the required packages, let’s import the Docker GPG key. This key enables your system to verify the integrity of packages downloaded from the Docker repository.

Use the following commands to download and save the GPG key:

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

The curl command fetches the GPG key from the Docker repository, which is then processed by gpg --dearmor to convert it into the binary format that apt requires.

Step 3: Add Docker CE APT Repository on Debian

With the GPG key in place, you can now import the Docker repository. Here’s the command to accomplish that:

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

This complex-looking command adds the Docker repository to your system’s source list and links it to the previously downloaded GPG key. This link verifies the integrity of the packages downloaded from the Docker repository, keeping your system secure.

Install Docker on Debian 12, 11, or 10 via APT

This section outlines the necessary steps to install Docker CE on your Debian system. You’ll learn how to update your system’s repository information, install Docker, and verify the installation by executing a test Docker image. Moreover, the section includes a crucial security practice to ensure the secure handling of Docker containers and images.

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

Before initiating the Docker installation, ensuring that your system’s repository information is up-to-date is advantageous, particularly with the recently added Docker repository. To update the repository information, execute the following command:

sudo apt update

This command refreshes your system’s package lists, including the details about the latest versions of packages and their dependencies.

Step 2: Install Docker on Debian 12, 11 or 10

With the system’s repository information updated, you can proceed with the Docker installation. Here’s the command to install Docker along with some additional plugins that enhance your Docker experience:

sudo apt install docker-ce docker-ce-cli docker-buildx-plugin docker-compose-plugin

In this command, you’re installing docker-ce (Docker Community Edition), docker-ce-cli (the Docker command-line interface), (an industry-standard runtime), and two useful Docker plugins for building images and managing multi-container applications.

Step 3: Verify Docker CE Installation on Debian

After completing the Docker installation, prudently verify its correct installation by running a test Docker image:

sudo docker run hello-world

This command pulls the hello-world image from the Docker repository, creates a new container from this image, and runs the container. When executed, it prints a welcome message, thus confirming that Docker is functioning as expected.

Screenshot of Docker Hello World command output on Debian Linux.
Screenshot showing the output of the Docker Hello World command on Debian Linux.

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

For security reasons, configure Docker to run as a non-root user. This practice safeguards your system against accidental or malicious changes that could cause harm. A later section will discuss this aspect more thoroughly.

Docker Troubleshooting Tip

While interacting with Docker containers and images, if you encounter any issues, a system reboot might help resolve them, particularly ones related to path generation. To restart your system, use the following command:


Managing Docker via Systemd on Debian 12, 11, or 10

This segment’ll explore how to manipulate Docker service using systemd. Systemd is a fundamental component of many Linux distributions, including Debian, which provides functionalities to administer system processes and services. As Docker installs a systemd unit on your Debian system, this presents an efficient way to manage the Docker service.

Starting the Docker Service on Debian via systemd

To utilize Docker, the Docker service must be actively running on your Debian system. Systemd facilitates this through the following command:

systemctl start docker.service

This command starts the Docker service and configures it to launch automatically upon system boot, ensuring its availability after each startup.

Stop Docker Service on Debian via systemd

In certain circumstances, you may want to stop the Docker service. Systemd provides a straightforward command to accomplish this:

systemctl stop docker.service

This command halts the Docker service and prevents it from starting automatically on the next system boot.

Restart Docker Service on Debian via systemd

You may sometimes want to restart the Docker service, especially when troubleshooting Docker-related issues. Systemd provides the functionality to restart the Docker service with this command:

systemctl restart docker.service

This command stops and starts the Docker service, effectively applying the most recent configurations.

Check Docker Service Status on Debian via systemd

To check the operational status of the Docker service, whether it’s running, stopped, or inactive, you can use the following systemd command:

systemctl status docker.service

The command fetches and displays the current status of the Docker service, providing insights into its operational condition.

Enable Docker Service on Debian System Boot via systemd

If you wish the Docker service to start automatically at system boot, enabling it through systemd is the preferred method:

systemctl enable docker.service

This command adjusts the Docker service settings to start automatically at each system boot, providing continuous availability of Docker functionalities.

Disable Docker Service on System Boot via systemd

If you decide not to have the Docker service automatically start during system boot, systemd can accommodate this request with the following command:

systemctl disable docker.service

This command alters the Docker service settings, preventing it from initiating automatically at system boot.

Utilizing systemd commands, you can effectively manage the Docker service on your Debian system, providing a high degree of control over Docker’s operational behavior. The following sections will dive into more specifics about utilizing Docker and managing Docker containers and images.

Configure Docker on Debian 12, 11 or 10

In this guide portion, we delve into setting up Docker configurations. This includes managing Docker as a non-root user, which enhances security, and altering the default logging driver to better suit your needs.

Step 1: Run Docker as a Non-Root User

While you can run Docker as a root user, doing so is discouraged because of potential security risks and accidental modifications to your Debian host system. Instead, manage Docker operations under a non-root user account to enhance security.

To create a new user specifically for Docker management, execute the following commands:

sudo useradd -m dockeruser
sudo usermod -aG docker dockeruser

These commands create a new user named ‘dockeruser’ and append this user to the Docker group. Being a member of the Docker group grants a user the necessary permissions to run Docker commands.

If you wish to assign your current user to the Docker group, replace ‘dockeruser’ with your username. For instance, for a user named ‘joshua’, the command would be:

sudo usermod -aG docker joshua

After making these changes, log out and back in to apply the modifications. Sometimes, you might need to restart the system to propagate these changes.

To confirm the user has permission to run Docker commands, use the following command:

docker ps

The command should display a list of running Docker containers, signifying a successful Docker installation.

Step 2: Modify Default Docker Logging Driver on Debian

Docker, by default, logs events in JSON file format. Nonetheless, Docker’s flexibility allows you to change the default logging driver to a different format or even configure it to forward logs to a remote log management system.

To modify the default logging driver, you need to create a new file called daemon.json in the /etc/docker/ directory. Utilizing a text editor such as nano, execute the following command:

sudo nano /etc/docker/daemon.json

When the file is open, paste the following content into it:

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

Docker uses the syslog driver in this configuration, and relays logs to a remote syslog server. Replace with your syslog server’s address.

Once the configuration is in place, restart the Docker daemon using the following command to apply the new logging driver settings:

sudo systemctl restart docker.service

Please remember any modifications made to the daemon.json file necessitate a Docker daemon restart for the changes to be applied.

Docker Command Examples on Debian 12, 11 or 10

In this segment, we delve into the usage of Docker commands that play a vital role in effectively managing Docker containers, images, networks, and volumes. The docker command provides a robust and versatile toolset designed to simplify and automate tasks in your Docker environment.

Fundamentals of Docker Commands on Debian

Familiarizing oneself with the Docker command line interface (CLI) is essential to mastering Docker. Below is an assortment of commands you’ll frequently encounter in your Docker journey:

  • 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.

Each command has a unique set of options that allow you to modify its behavior to meet your needs. Let’s explore each command and its respective options.

The docker run Command

The docker run command creates a new container from a specified image. For example, to initiate a container from the Debian image and open an interactive shell within it, use the following command:

docker run -it debian:latest /bin/bash

The docker ps Command

The docker ps command is deployed to enlist all currently active containers. It reveals valuable information about each container, including container ID, associated image, and running status. To get a list of all running containers, simply type:

docker ps

The docker images Command

The docker images command is tasked with listing all locally available Docker images. It returns information about each image, including its ID, associated repository, and tag:

docker images

The docker build Command

The docker build command is used to create a new Docker image from a Dockerfile. A Dockerfile is essentially a script housing instructions for constructing a Docker image. For example, to build a new image named ‘myimage’ using the Dockerfile in the current directory, you’d use the following command:

docker build -t myimage:latest .

The docker stop Command

The docker stop command gracefully terminates a running Docker container. You can target the desired container using its ID. For example, to stop a container with ID ‘abcdefg,’ you’d use:

docker stop abcdefg

The docker rm Command

Use the docker rm command to delete a Docker container. Like the stop command, specify the container ID of the container you wish to delete. For example:

docker rm abcdefg

The docker rmi Command

Use the docker rmi command to remove Docker images. Identify the image you want to delete by its ID. For example:

docker rmi 1234567

The docker network Command

The docker network command is a versatile tool for creating, listing, and removing Docker networks. For instance, to create a new network named ‘mynetwork,’ you’d use:

docker network create mynetwork

The docker volume Command

Finally, the docker volume command offers functionalities to manage Docker volumes. For instance, to create a new volume named ‘myvolume,’ you would use:

docker volume create myvolume

Navigating Docker Container Management

Effectively managing Docker containers significantly influences the functionality and longevity of a Docker environment. The docker command provides a variety of crucial sub-commands for manipulating Docker containers. These sub-commands facilitate container creation, operation, modification, and deletion. Whether you are a seasoned developer or a beginner in containerization, understanding these commands can enhance your Docker interaction substantially.

Core Commands for Docker Container Management with Debian

The command docker ps is an essential tool in your Docker toolkit for enumerating all running containers. By executing this command, you can see all active containers, their corresponding image, status, and unique container ID.

docker ps

To terminate a currently active Docker container, the docker stop command is deployed. You append the unique ID or name of the container you want to stop.

docker stop abcdefg

The docker rm command is used to eradicate a Docker container. This command, like docker stop, accepts either the container’s unique ID or name as an argument.

docker rm abcdefg

It’s crucial to note that deleting a container discards any modifications made. To retain changes, you must create a new image from the modified container using the ‘docker commit’ command.

Retaining Container Changes using docker commit

While working with Docker containers, you might need to customize a container and preserve these alterations as a new image. This can be accomplished using the docker commit command.

Initiate a new container using a base image and make the necessary alterations within this container. For instance, consider starting a new container from the Debian image and opening a shell inside the container:

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

You can perform various tasks in this new container, such as modifying configuration files or installing new software. After making the desired changes, use the docker commit command to produce a new image encapsulating these alterations. To create a new image named ‘myimage’ with the changes made in the ‘mycontainer’ container, execute the following command:

docker commit mycontainer myimage:latest

You now possess an image named ‘myimage’, incorporating changes made in the ‘mycontainer’ container. Use this new image to generate and operate new containers with updated configurations or software.

Remember, the docker commit command only saves modifications made to the container’s filesystem, not preserving changes to networking and storage. If retaining changes in networking and storage is necessary, consider using other Docker commands like docker network and docker volume.

Wrapping Up

We delved into installing and managing Docker Community Edition (CE) on a Debian Linux distribution throughout our discussion. Docker CE brings all the benefits of containerization, allowing developers to build, ship, and run distributed applications in different environments. The Docker commands and use cases discussed here offer foundational knowledge for managing Docker containers. While the article touched on fundamental Docker commands like docker run, docker ps, docker rm, and others.

Remember that the Docker ecosystem is much broader, with numerous commands and options that you can explore to fine-tune your Docker experience.