How to Install Docker CE on Debian 12

Introduction:

One containerization platform is called Docker. Developers can package the apps and other dependencies into isolated, lightweight containers with this feature. This approach guarantees portability and consistency in many contexts. Docker is perfect for delivering programs from local development environments to cloud infrastructures because of its effective containerization, which reduces the overhead of virtualization. Docker allows developers to share, distribute, and grow their applications with ease. In addition to promoting DevOps principles, this speeds the development process. Developer collaboration is encouraged and applications may be deployed quickly thanks to its extensive ecosystem of pre-built images and Docker Hub repository. Docker is therefore a crucial tool for contemporary software development. We’ll walk you through How to Install Docker CE on Debian 12 “Bookworm” in this article.

Prerequisites:

Be advised that when you expose container ports via Docker, your firewall rules are circumvented if you use UFW or Firewalld to handle your firewall settings. See Docker and UFW for further details.

You must have one of the following Debian versions in 64-bit format in order to install Docker Engine:

  • Debian Bookworm 12 (stable)
  • Debian Bullseye 11 (oldstable)

Docker Engine for Debian is compatible with x86_64 (or amd64), armhf, arm64, and ppc64le (ppc64el) architectures.

Uninstall old versions:

You must remove any incompatible packages before proceeding with the installation of Docker Engine.

Unofficial releases of Docker packages are made available by distro maintainers through their repositories. Before you install the official version of Docker Engine, you must uninstall these packages.

 

Step 1. Update the System:

Initially, we must use SSH to access our Debian 12 VPS:

ssh root@IP_Address -p Port_number

If required, replace “root” with the user who has sudo access or root. Additionally, enter the IP address and SSH port number of your server in place of “IP_Address” and “Port_Number.” Let’s check that we are running Debian 12 next. You can carry it out as follows:

# lsb_release -a

The following output should be produced by the command:

There are no LSB modules available.
ID of Distributor: Debian
Release date: 12; Description: Debian GNU/Linux 12 (bookworm)
Code-name: reader

Step 2. Install Docker:

Depending on your needs, there are several ways to install Docker on a Debian 12 system:

Install Docker Engine from Docker’s Apt repository.

We can easily do the update using this method, which makes it the best and most recommended approach to install Docker. You must set up the Docker Apt repository before installing Docker Engine for the first time on a fresh host system. After that, Docker can be updated and installed via the repository.
Run these commands to add and configure the Apt repository for Docker.

# apt update
# apt install ca-certificates curl gnupg
# install -m 0755 -d /etc/apt/keyrings
# curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# chmod a+r /etc/apt/keyrings/docker.gpg

Then, add Docker’s APT repository to the APT source.

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" | \
   tee /etc/apt/sources.list.d/docker.list > /dev/null

Update the system’s package index files after adding a new package.

# apt update

Finally, install the docker packages.

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

That’s all; your Debian system now has Docker installed. To confirm the installation, we can execute the command listed below.

# docker version

You’ll see an output similar to this one:

Client: Docker Engine - Community
 Version:           24.0.6
 API version:       1.43
 Go version:        go1.20.7
 Git commit:        ed223bc
 Built:             Mon Sep  4 12:32:10 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.6
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.7
  Git commit:       1a79695
  Built:            Mon Sep  4 12:32:10 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

Additionally, you might try executing the following command on a basic Docker image:

# docker run hello-world

The aforementioned command will launch a test image in a container and download it. The container prints a confirmation message upon execution and then shuts down.
An error message may appear if you execute the command as a regular system user without sudo capabilities. Therefore, you can add the user to the docker’s group by running the command below if you wish to run docker commands without using sudo.

# usermod -aG docker $USER
# newgrp docker

Do not forget to replace $USER with your actual system user.

Install it and manage the upgrade manually.

This method allows us to install docker by downloading .deb packages and then simply installing the packages. To proceed with this installation method, follow these steps.

Navigate to the Docker download page.

Download the following deb files for the Docker Engine, CLI, containers, and Docker Compose packages:

containerd.io_<version>_<arch>.deb
docker-ce_<version>_<arch>.deb
docker-ce-cli_<version>_<arch>.deb
docker-buildx-plugin_<version>_<arch>.deb
docker-compose-plugin_<version>_<arch>.deb

For example, we will download these files.

wget https://download.docker.com/linux/debian/dists/bookworm/pool/stable/amd64/containerd.io_1.6.22-1_amd64.deb
wget https://download.docker.com/linux/debian/dists/bookworm/pool/stable/amd64/docker-ce_24.0.6-1~debian.12~bookworm_amd64.deb
wget https://download.docker.com/linux/debian/dists/bookworm/pool/stable/amd64/docker-ce-cli_24.0.6-1~debian.12~bookworm_amd64.deb
wget https://download.docker.com/linux/debian/dists/bookworm/pool/stable/amd64/docker-buildx-plugin_0.11.2-1~debian.12~bookworm_amd64.deb
wget https://download.docker.com/linux/debian/dists/bookworm/pool/stable/amd64/docker-compose-plugin_2.21.0-1~debian.12~bookworm_amd64.deb

Install the files by running this command:

dpkg -i ./containerd.io_<version>_<arch>.deb \
  ./docker-ce_<version>_<arch>.deb \
  ./docker-ce-cli_<version>_<arch>.deb \
  ./docker-buildx-plugin_<version>_<arch>.deb \
  ./docker-compose-plugin_<version>_<arch>.deb

Or, if you download the same files as mentioned in this article, run this command:

dpkg -i ./containerd.io_1.6.22-1_amd64.deb \
  ./docker-ce_24.0.6-1~debian.12~bookworm_amd64.deb \
  ./docker-ce-cli_24.0.6-1~debian.12~bookworm_amd64.deb \
  ./docker-buildx-plugin_0.11.2-1~debian.12~bookworm_amd64.deb \
  ./docker-compose-plugin_2.21.0-1~debian.12~bookworm_amd64.deb

The Docker daemon starts automatically upon installation.

Verify that the Docker Engine installation is successful by running the hello-world image:

# service docker start
# docker run hello-world

Another method is to install docker using a script. But, this is recommended only for test and development environments. If you want to try this method, you can execute these commands.

# curl -fsSL https://get.docker.com -o get-docker.sh
# sh get-docker.sh

The script will install and start docker immediately.

Conclusion:

We have looked at the detailed procedure for installing Docker on Debian 12 (Bookworm) throughout this article.It is important to remember that Docker is always changing, with new updates, enhancements, and features being added on a regular basis. Therefore, in order to guarantee a seamless and safe Docker experience, it is advised to stay current with the most recent releases and security updates.

See the official Docker docs for additional information. If you want to learn more about Docker and how to use Docker Compose to run and manage multi-container applications, we also suggest reading our comprehensive tutorial. Cheers to docking!

Leave a Reply

Your email address will not be published. Required fields are marked *