How to Install Docker on Debian 12

Choose a different version or distribution

Introduction

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

Docker is an open-source platform that simplifies the process of building, deploying, and managing applications. It enables users to package applications and their dependencies into a lightweight container, making them portable across different environments.

With Docker, developers can easily isolate their applications, ensuring consistent behavior across development, testing, and production environments. This technology revolutionizes software delivery by enhancing scalability, efficiency, and collaboration. Learn more about Docker's benefits and how it can enhance your application deployment process.

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

Advantages of Docker

  1. Portability: Docker containers can run consistently on any host, providing consistent behavior across different environments.
  2. Scalability: Docker allows effortless scaling of applications, with the ability to spin up or down containers based on demand.
  3. Efficiency: Docker's lightweight containers enable faster deployment and reduced resource consumption.
  4. Isolation: Applications running in Docker containers are isolated from one another, ensuring no interference or conflicts.
  5. Collaboration: Docker simplifies collaboration among team members by providing a standardized environment that can be easily shared and reproduced.

Install Docker on Debian

To install the most recent stable version of Docker from the Docker repositories, follow these instructions.

01. Install the required packages to add a new repository over HTTPS:

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg2

02. Use the following curl command to import the repository's GPG key:

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

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

The command will return OK if it is successful.

03. The stable Docker APT repository should be added to your system's list of software repositories:

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

$(lsb release -cs) returns the Debian distribution name. It is buster in this case.

04. Install the most recent version of Docker CE (Community Edition) and update the apt package list:

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

05. The Docker service will start automatically after the installation is complete. To check, type in:

sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-07-30 20:52:00 GMT; 1min 11s ago
    Docs: https://docs.docker.com
...

06. The most recent stable version of Docker is 24.0.5 as of this writing:

docker -v
Output

Docker version 24.0.5, build ced0996

Executing the Docker Command Without Sudo

By default, only root and users with sudo privileges can run Docker commands.

You must add your user to the docker group that is generated during the installation of the Docker CE package if you wish to run Docker commands without prepending sudo. You can do that by typing:

sudo usermod -aG docker $USER

Your username is stored in the environment variable $USER.

Log out and back in again to refresh the group membership.

Once finished, type the following to confirm that you can run docker commands without sudo:

docker container run hello-world

The command will download a test image, execute it within a container, print a message saying "Hello from Docker," and then exit. The output should seem as follows:

Using Docker

Now that you have Docker installed on your Debian 12 system, let us review the fundamental ideas and commands of Docker.

Docker Images

A Docker image consists of a number of filesystem levels that correspond to the instructions in the Dockerfile that make up an executable software application. An image is an immutable binary file that contains the application together with any additional dependencies, including any libraries, binaries, or instructions required for the application to function.

The majority of Docker images are accessible through Docker Hub. It is a cloud-based registry service that is used, among other features, to store Docker images in either a public or private repository.

Use the docker search command to look for an image in the Docker Hub registry. For example, to find a Debian image, you would type:

docker search debian

Docker Containers

A container is an instance of an image. For a single application, process, or service, a container represents the runtime.

Although it may not be the best analogy, if you are a programmer, you may consider a Docker image to be a class and a Docker container to be an instance of that class.

Use the docker container command to manage, start, stop, and remove containers. The following command, for instance, will launch a Docker container based on the Debian image.  If you do not have the image locally, it will be downloaded first:

docker container run debian

Due to the lack of a long-running process and the absence of any further commands, the Debian container will shut down soon after starting. The container started up, executed a blank command, and then exited.

You can interact with the container using the command line by using the switch -it. To start an interactive container type, do the following:

docker container run -it debian /bin/bash
Output

root@ee86c8c81b3b:/#

As you can see from the output above, the command prompt changes once the container is started, indicating that you are now operating from inside the container.

Use the following command to list all running Docker containers:

docker container ls

The output will be blank if no containers are currently running.

Pass the -a switch to display all containers:

docker container ls -a

Simply copy the container ID (or IDs) and paste them after the container rm command to delete one or more containers:

docker container rm c55680af670c

FAQs to Install Docker on Debian 12

How can I confirm if Docker is installed correctly? 

Run sudo docker version to check the installed Docker version and verify its successful installation.

What are the system requirements for Docker on Debian 12? 

Docker requires a 64-bit Debian 12 system with kernel version 3.10 or later, and at least 2GB of RAM.

How can I start and enable Docker on system boot? 

Use the following command: sudo systemctl enable --now docker

Can Docker be installed without root access? 

Yes, you can use Docker as a non-root user. Follow the official Docker documentation to create a Docker user group and add your user to it.

Is it necessary to restart the system after installing Docker? 

No, you don't need to restart the system. Docker can be used immediately after installation.

How can I add my user to the Docker group? 

Add your user to the Docker group with the following command: sudo usermod -aG docker your_username.

How do I pull and run a Docker image? 

Use the docker run command followed by the image name. For example: docker run image_name.

Conclusion

Docker installation on Debian 12 is a rather simple process. The de facto container technology standard, Docker, is a crucial tool for DevOps engineers and their continuous integration and delivery pipeline.

Visit the official Docker documentation to learn more about Docker.

If you have any suggestions or queries, kindly leave them in the comments section.