Table of Contents
why we need docker?
Docker is a powerful platform that simplifies the process of developing, packaging, and deploying applications.
Docker is widely used in the software development and IT industries. Docker uses containerization, allowing applications and their dependencies to be packaged together. This ensures consistency across different environments, making it easy to deploy applications on various platforms. Containers provide a level of isolation, meaning that each application runs in its own container with its own dependencies. This isolation minimizes conflicts between applications and enhances security.
Most important benefit of using docker containers can run on any machine that has Docker installed, regardless of the underlying operating system. This portability simplifies the deployment process and reduces compatibility issues, and makes it straightforward to scale applications horizontally by running multiple containers. This is particularly useful for microservices architectures and applications that need to handle varying workloads.
In this article we will be using docker installation manual for reference or more detail follow the link.
Task
How to install docker in Debain 12?
Short solution: installing docker
Use the following commands to install latest docker version in debain 12 if you want to install sepcific version please scroll down for the Installing specific Version subsection.
# Add Docker's official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl gnupg -y 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 # Add the repository to Apt sources: 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 sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Explaination
Prequisite
- For Docker installation, ensure you have the 64-bit version of one of these Debian versions. Docker Engine for Debian is compatible with architectures such as x86_64 (or amd64), armhf, arm64, and ppc64le (ppc64el). In our previous article we have talked about how to install debian12
- Also remove the old docker or any docker related installed packages.
- Installing base packages which are required to install the docker and re-configuring them. For docker ca-certificates, curl and gnupg packages are required, to install them we will use the following commands
# Add Docker's official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl gnupg -y
- Following command used to copy files and set attributes. In this context, it is used to create directories /etc/apt/keyrings with permissions (mode) of the directory 0755, which means read, write, and execute permission for the owner, and read and execute permission for others.
sudo install -m 0755 -d /etc/apt/keyrings
- Following command downloads the Docker GPG key, dearmors it, and saves it as a binary file named “docker.gpg” in the “/etc/apt/keyrings/” directory. This key is commonly used for securely verifying the authenticity of Docker packages during installation or updates on a Debian system
- In the next command it adds read permission for all users to the Docker GPG key file, allowing any user on the system to read (but not modify) the contents of the file.
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
Add the repository to Apt sources and update the repo so that your system has the latest information about available packages,
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 sudo apt-get update
Installing Docker
Latest Docker installation
Following command install the latest docker packages. You can also install particular version we will installing the following packages ensuring docker
- docker-ce: This package encompasses the Docker daemon, client, and supplementary tools.
- docker-ce-cli: It is the command-line interface (CLI) for Docker, facilitating user interaction through commands.
- containerd.io: This package furnishes the fundamental functionalities required for container execution.
- docker-buildx-plugin: Extending the capabilities of the standard Docker Build command, this plugin enables multi-platform builds and offers additional features.
- docker-compose-plugin: this plugin empowers users to define and execute multi-container Docker applications.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Installing specific Version
To install a particular version of Docker packages, begin by displaying the list of versions accessible in the repository.
apt-cache madison docker-ce | awk '{ print $3 }' Output.. docker-ce/bookworm 5:25.0.0-1~debian.12~bookworm amd64 docker-ce/bookworm 5:24.0.7-1~debian.12~bookworm amd64 docker-ce/bookworm 5:24.0.6-1~debian.12~bookworm amd64 docker-ce/bookworm 5:24.0.5-1~debian.12~bookworm amd64 ...
Select the desired version and install:
VERSION_STRING=5:25.0.0-1~debian.12~bookworm sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
Testing
Confirm that Docker is installed correctly by running the following command in the terminal
docker --version
You can also try some more basic commands like, which obviously don’t show anything but at least it will validate that docker is properly installed, see the command and their outputs.
foofunc@debian-test:~$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES foofunc@debian-test:~$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE
To launch a simplest container, “hello-world” Docker container serves as an excellent example. Use the following command: it will download the “hello-world” image and start the “hello-world” container.
foofunc@debian-test:~$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c1ec31eb5944: Pull complete Digest: sha256:4bd78111b6914a99dbc560e6a20eab57ff6655aea4a80c50b0c5491968cbc2e6 Status: Downloaded newer image for hello-world:latest WARNING: IPv4 forwarding is disabled. Networking will not work. Hello from Docker! ...