Containerization has emerged as a game-changing technology in the IT industry, revolutionizing how applications are being developed and managed. It involves bundling an application and its libraries within a lightweight, self-contained unit called a container. This encapsulation of code and all the binaries eliminates the compatibility issues on various systems both on-prem and in the cloud. This results in faster and more efficient workflows with easier building, testing and deployment of applications. The containers also provide a portable and isolated environment, that makes it possible to run executions across different environments. Containerization technology has also brought several tools into play. These tools include Kubernetes, Podman and Docker
Docker is an open-source container runtime engine that allows you to build, run and manage containers. The Docker Engine was introduced in 2013 as an industry-standard tool to provide a universal packaging approach. Today, this tool has been adopted in several organizations where applications need to be created and modernized for the cloud.
Docker consists of the following components:
- Docker Engine: This is the runtime responsible for executing and managing Docker containers on the host system. It provides an API and command-line interface (CLI) for interacting with containers.
- Docker Images: These are templates defining the contents and configuration of a container. Images are usually built from a set of declarative variables called Dockerfiles which can be versioned and shared across different environments.
- Docker Registry: This is a public and central repository used to store and share Docker images. The Docker Hub is the default public registry, although you can also set up and use private registries.
- Docker Compose: This tool is used to define and manage multi-container applications. It allows you to use a single YAML file to specify the configuration and relationships between different containers.
Install Docker on Debian 12 (Bookworm)
In this guide, we will learn how to install Docker on Debian 12 (Bookworm).
Step 1: Update your System
It is always important to work with a system that is up to date with all the packages updated. To do that, issue the below command on your shell:
sudo apt -y update && sudo apt -y upgrade
You also need to check if a reboot is required after the update:
[ -f /var/run/reboot-required ] && sudo reboot -f
Step 2: Add Docker’s official Stable Repository
To be able to install Docker and all the required packages, we need to add the official repository to our Debian 12 system. We will start by installing the required packages:
sudo apt install lsb-release gnupg2 apt-transport-https ca-certificates curl software-properties-common -y
Next, import the GPG keys for the Docker repository:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/debian.gpg
Now add the Docker stable repository:
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
Step 3: Install Docker CE Debian 12 (Bookworm)
Once the repository has been added, you can proceed and install Docker on Debian 12 (Bookworm) using the commands below:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Once the installation is complete, you need to add your user to the Docker group to be able to run Docker commands without using sudo
sudo usermod -aG docker $USER
newgrp docker
Also ensure that the Docker service is started and enabled:
sudo systemctl start docker && sudo systemctl enable docker
Check if the service is running:
$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; preset: enabled)
Active: active (running) since Mon 2023-06-26 05:59:29 EDT; 41s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 2874 (dockerd)
Tasks: 8
Memory: 27.2M
CPU: 254ms
CGroup: /system.slice/docker.service
└─2874 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Check the installed version:
$ docker version
Client: Docker Engine - Community
Version: 24.0.4
API version: 1.43
Go version: go1.20.5
Git commit: 3713ee1
Built: Fri Jul 7 14:51:00 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.4
API version: 1.43 (minimum version 1.12)
Go version: go1.20.5
Git commit: 4ffc614
Built: Fri Jul 7 14:51:00 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.21
GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8
runc:
Version: 1.1.7
GitCommit: v1.1.7-0-g860f061
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Step 4: Using Docker on Debian 12 (Bookworm)
After installing Docker, you can use it to manage the containers as desired. Here are some of the basic operations of Docker.
i. Pulling Container Images
With Docker, you can pull container images from the desired container registry. To achieve that, use the command with the below syntax:
docker pull <registry/image:tag>
When pulling an image without specifying the container registry, Docker will attempt to pull from the default Docker Hub registry.
For example:
$ docker pull nginx:latest
latest: Pulling from library/nginx
5b5fe70539cd: Pull complete
441a1b465367: Pull complete
3b9543f2b500: Pull complete
ca89ed5461a9: Pull complete
b0e1283145af: Pull complete
4b98867cde79: Pull complete
4a85ce26214d: Pull complete
Digest: sha256:593dac25b7733ffb7afe1a72649a43e574778bf025ad60514ef40f6b5d606247
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
Once the images have been pulled, you can view them with the command:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest eb4a57159180 12 days ago 187MB
To delete the image, use:
docker rmi <registry/image:tag>
##OR
docker rmi <Image_ID>
For example;
docker rmi nginx:latest
##OR
docker rmi eb4a57159180
ii. Building Container Images
Aside from pulling container images, you can also create your own image for local use or push them to your registry for later use.
To build an image, you need to create a declarative Dockerfile:
vim Dockerfile
In the file, you can add your desired variables:
FROM ubuntu:20.04
RUN apt-get update -y
ENV DEBIAN_FRONTEND=noninteractive
RUN apt install -y gnupg apt-transport-https apt-utils wget
RUN echo "deb https://notesalexp.org/tesseract-ocr5/focal/ focal main" \
|tee /etc/apt/sources.list.d/notesalexp.list > /dev/null
RUN wget -O - https://notesalexp.org/debian/alexp_key.asc | apt-key add -
RUN apt-get update -y
RUN apt-get install tesseract-ocr -y
RUN apt install imagemagick -y
ENTRYPOINT ["tesseract"]
RUN tesseract -v
Now with the file, you can build the image with the command:
docker build . -t tesseract:5
Once complete, check if the image exists:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tesseract 5 4940099b2240 11 seconds ago 312MB
nginx latest eb4a57159180 12 days ago 187MB
iii. Pushing Images to Registry
After building, you can consume the image locally or push it to a registry. Docker allows you to push images to the Docker Hub registry as well as other private/public registries.
To push to the Docker hub registry, first log in with the command:
docker login
Once authenticated, you can push the images with the command:
docker push <Image_name>
To learn more about private and public registries, you can view the below guides:
- Configure GitHub Container Registry as your Docker Registry
- Install and Use Trow Container Image Registry With Kubernetes
- Install Harbor Image Registry on Ubuntu
iv. Manage Containers with Docker
You can start, stop and manage containers as desired using Docker. You can run containers form existing images or pull and use them directly.
To use a locally available image, provide the image name. For example:
$ docker run tesseract:5 -v
tesseract 5.3.1
leptonica-1.79.0
libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 2.0.3) : libpng 1.6.37 : libtiff 4.1.0 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.1
Found AVX2
Found AVX
Found FMA
Found SSE4.1
Found OpenMP 201511
Found libarchive 3.4.0 zlib/1.2.11 liblzma/5.2.4 bz2lib/1.0.8 liblz4/1.9.2 libzstd/1.4.4
Found libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
You can also use an image that is in the registry. For example:
docker run hello-world
Sample Output:
View the available containers:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad88fafb30ec hello-world "/hello" 26 seconds ago Exited (0) 25 seconds ago trusting_lederberg
a1721e30eb1e tesseract:5 "tesseract -h" 45 seconds ago Exited (0) 44 seconds ago dazzling_lehmann
51816cac70ed tesseract:5 "tesseract --version" 55 seconds ago Exited (0) 54 seconds ago hopeful_mclaren
6ce6654f31a4 tesseract:5 "tesseract -v" About a minute ago Exited (0) About a minute ago laughing_engelbart
To stop a Docker container, use the command with the below syntax:
docker stop container_name/container_ID
To delete a container, use:
docker rm container_name/container_ID
v. Manage Containers Using Docker Compose
Docker compose is used to managing multiple containers in one YAML file. This comes in handy when dealing with a large environment with a lot of containers.
Learn how to install and use Docker-compose on Debian 12 (Bookworm) by following the below guide:
Step 5: Uninstall Docker on Debian 12 (Bookworm)
It is also possible to uninstall Docker any time whenever you feel you do not need it. To achieve that, run the below command on your Debian 12 (Bookworm):
sudo apt remove docker-ce docker-ce-cli containerd.io
After this command, the images, containers, volumes, or customized configuration files will not be removed. You need to manually delete them:
sudo rm -rf /var/lib/docker
You also need to remove the containerd runtime directory:
sudo rm -rf /var/lib/containerd
Conclusion
That is the end of this guide. This guide has provided a detailed demonstration of how to install Docker on Debian 12 (Bookworm). You are now free to explore the awesomeness of Docker on Debian 12 (Bookworm). Luckily, there are dedicated guides on this page to help you.
See more:
- Run Greenbone Vulnerability Management in Docker Container
- Run Teleport in Docker Container using Docker Compose
- How To Run and Use Dnsmasq in Docker Container
- How To Run Asterisk in Docker Container