Containers are lightweight, portable, and consistent, which makes them ideal for developing, testing, and deploying applications across different platforms and environments. If you want to use Docker on your Debian 12 system, you need to install the Docker Engine, which is the core component of the Docker platform.
The Docker Engine is responsible for creating and managing containers, images, networks, volumes, and other Docker objects. In this guide, we will show you how to install the Docker Engine on Debian 12 using the official Docker repository.
We will also show you how to manage Docker as a non-root user, configure Docker to start on boot, test Docker functionality, and optionally install Docker Compose, which is a tool that helps you define and run multi-container applications with ease.
- A Debian 12 system with a sudo-enabled user account
- A working internet connection.
- Need to have curl installed on your system, which you can do by running
sudo apt install curlif you don’t have it already.
Update System and Install Dependencies
The first step is to update your system and install some dependencies that are required for installing the Docker Engine. To do this, open a terminal window and run the following commands:
sudo apt update sudo apt upgrade sudo apt install apt-transport-https ca-certificates gnupg lsb-release
apt-transport-https package allows you to access repositories that use HTTPS. The
ca-certificates package provides certificates that are used to verify the authenticity of HTTPS connections. The
gnupg package enables you to manage cryptographic keys that are used to sign packages. The
lsb-release package provides information about your Linux distribution.
Add the Official Docker Repository
The next step is to add the official Docker repository to your system. This will allow you to install the latest version of the Docker Engine and receive updates from the Docker team. To add the official Docker repository, run 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 sudo chmod a+r /etc/apt/keyrings/docker.gpg
Now setup the repository with the below command.
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
Update the package index.
sudo apt update
Install Docker Engine
Now that you have added the official Docker repository, you can install the Docker Engine on your system. To do this, run the following commands:
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io
docker-ce package installs the Docker Engine community edition, which is the free version of the Docker platform.
docker-ce-cli package installs the Docker command-line interface, which allows you to interact with the Docker Engine.
containerd.io package installs the containerd runtime, which is a dependency of the Docker Engine.
Check Docker version using the below command:
You will see an output similar to the one below.
Client: Docker Engine - Community Version: 24.0.5 API version: 1.43 Go version: go1.20.6 Git commit: ced0996 Built: Fri Jul 21 20:35:18 2023 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 24.0.5 API version: 1.43 (minimum version 1.12) Go version: go1.20.6 Git commit: a61e2b4 Built: Fri Jul 21 20:35:18 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.22 GitCommit: 8165feabfdfe38c65b599c4993d227328c231fca runc: Version: 1.1.8 GitCommit: v1.1.8-0-g82f18fe docker-init: Version: 0.19.0 GitCommit: de40ad0
Manage Docker as a non-root user
By default, only the root user or users with sudo privileges can run docker commands on Debian 12. However, this is not recommended for security reasons, as it can expose your system to potential risks. To avoid this, you can create a docker group and add your user account to it. This will allow you to run docker commands without sudo.
To create a docker group and add your user account to it, run the following commands:
sudo groupadd docker sudo usermod -aG docker $USER
The first command creates a docker group if it does not exist already. The second command adds your user account to the docker group.
To apply the changes, you need to log out and log back in to your system. Alternatively, you can run the following command to activate the changes in your current session:
Configure Docker to Start on Boot
By default, Docker is configured to start automatically when your system boots. However, if you want to change this behavior, you can use the
systemctl command to enable or disable Docker to start on boot.
To enable Docker to start on boot, run the following command:
sudo systemctl enable docker
To disable Docker to start on boot, run the following command:
sudo systemctl disable docker
You can also use the
systemctl command to start, stop, restart, or check the status of Docker at any time.
To start Docker, run the following command:
sudo systemctl start docker
To stop Docker, run the following command:
sudo systemctl stop docker
To restart Docker, run the following command:
sudo systemctl restart docker
To check the status of Docker, run the following command:
sudo systemctl status docker
You will get a response similar to the one below
● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2023-08-22 03:03:26 UTC; 10min ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 752 (dockerd) Tasks: 9 Memory: 90.1M CPU: 828ms
Test Docker Functionality
To test if Docker is working properly on your system, you can try to run a hello-world container and see its output. A container is a running instance of an image, which is a template that contains everything an application needs to run. The hello-world image is a simple image that prints a message and exits.
To run a hello-world container and see its output, run the following command:
docker run hello-world
You should see something like this:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 719385e32844: Pull complete Digest: sha256:dcba6daec718f547568c562956fa47e1b03673dd010fe6ee58ca806767031d1c Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. ...
The first time you run this command, Docker will pull the hello-world image from the Docker Hub, which is a public registry that hosts thousands of images for various applications and services. Then, Docker will create and run a container from the image and print its output. Finally, Docker will stop and remove the container automatically.
You can use various docker commands to manage containers on your system. For example, you can use the following commands to list, stop, and remove containers:
List all running containers:
List all containers including stopped ones also:
docker ps -a
Stop container by its ID:
docker stop <container-id>
Delete container by its ID:
docker rm <container-id>
Install Docker Compose (optional)
Docker Compose is an optional tool that helps you define and run multi-container applications with ease. With Docker Compose, you can use a YAML file to specify how your containers are connected, what ports they expose, what volumes they use, and other settings. Then, you can use a single command to create and start all the containers at once.
To install Docker Compose on your Debian 12 system, you need to download the latest binary from the GitHub repository and make it executable. To do this, run the following commands:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Configure executable permissions for Docker Compose
sudo chmod +x /usr/local/bin/docker-compose
The first command downloads the Docker Compose binary for your system architecture and saves it to
/usr/local/bin/docker-compose. The second command makes the binary executable.
To verify the installation and check the Docker Compose version, run the following command:
You should see something like this:
Docker Compose version v2.20.3
In this guide, we have shown you how to install the Docker Engine on Debian 12 using the official Docker repository. We have also shown you how to manage Docker as a non-root user, configure Docker to start on boot, test Docker functionality, and optionally install Docker Compose.
With these steps, you are ready to use Docker on your Debian 12 system and create and run various applications using containers.