How To Install and Use Docker Engine on Debian 11 Tutorial

How To Install and Use Docker Engine on Debian 11 Tutorial. In this tutorial we will introduce Docker Engine with their main advantages and after that we will move onto installation phase. We will also explain some basic Docker commands that are used to manage the Docker containers.

In the past few years Docker has grown exceptionally popular amongst organizations due to its features of creating simple tool and packaging approach that bundles up all application dependencies inside a container which then runs on Docker Engine.

Docker’s containers technology makes development highly scalable as it separates your applications from your infrastructure to be able to deliver software quickly. Shipping, testing and deploying the code is made quickly with less delays in applications delivery.

Docker became popular as organizations shifted to cloud native development and hybrid multi cloud environments.

What is Docker?

The Docker Engine (DE) is an open source containerization technology. It is the core component of the Docker that you install on the host machine. It is a lightweight, scalable runtime environment and a core client server technology that works by creating and containerizing your applications. 

A Docker engine is made up of three elements to act as a client server application:

  • Server: Server with a Docker daemon (dockerd) process. It is responsible to create and manage Docker objects such as containers, images, volumes and networks.
  • REST API: It is responsible to create communication link between Docker and programs. It helps ‘dockerd’ in its function using instructions.

The CLI makes use of Docker APIs to communicate and control the Docker daemon (dockerd) via direct commands or scripting. Even other Docker applications leverage the core CLI and API.

What are the Benefits of using Docker Engine?

Docker makes use of containers as a simple runtime environment for software applications. These share system resources and file system whilst running at OS level. Containerization does not use too many resources as compared to a VM (virtual machine) or a traditional server. 

With Docker, IT enterprises can seamlessly create, deploy, run and manage applications within containers. These containers are lightweight and include all dependencies and instructions inside them such as libraries, bins, frameworks, and so on.

Here are the major advantages of using a Docker Engine for software development:

1. Faster deployment

Since Docker is an isolated, virtualized OS environment; it is siloed from local infrastructure, which makes application deployment much faster and easier. It does not have a boot time when you start containers instances. Besides, you can even share already existing containers to build new applications. 

2. Better interface

Docker has become popular in past few years as it offers a highly accessible and systematic interface for containerization. It also comprises an open source software repository including base container images. Users can leverage this to build on as they create siloed container environments to run applications.

3. Saves time

DevOps experts can leverage Docker to containerize wide range of applications, without any interference with each other. These containers can be passed on to the quality team for independently testing the functions and processes of the system. Hence, Docker saves time and most importantly, it works on any platform. 

4. Consistency

Docker makes sure your applications run seamlessly within multiple environments without any failures. This ensures reliability as developers can work on same application running in different OS and machines without any runtime environment problems.

5. Automation

The Docker platform allows you to automate time consuming, repetitive manual tasks through scheduling. Thus, it boosts team production and greatly reduces human intervention.

6. Supports CI/CD

Docker aims to streamline CI/CD processes it as accelerates your deployments, enhances team efficiencies and simplifies the upgrading process.

7. Image version control and rollbacks

In Docker, a container is based upon an image that includes multiple layers. These layers denote every update and change that has ever occurred in the base. This provides you enhanced version control over the container, and helps you easily rollback to a previous version, as and when needed. Plus, this feature also accelerates the entire build process.

8. Cost effective

Containers are lightweight and small packages that do not entertain guest OS. It consumes less memory as compared to VMs and also reuses components, all credits to the images and data volumes. Also, its resource efficiency is higher as it runs entirely on cloud and does not require extensive physical servers.

9. Flexibility

Containers are siloed virtual environments. Each container has its own unique function within a multi container application. Since it has an independent environment, developers can easily work on a specific component of an application without taking the entire application down.

10. Swarm mode

A swarm is a cluster of connected Docker Engine hosts where application services can be started. Docker Engine can deploy manager and worker nodes from an image at runtime instead of deployment. Swarm mode maintains and returns the declared desired state in the event of an outage or scaling event.

11. Shared container libraries

Developers can use open source registry where there is thousands of containers.

12. Load Balancing

Container Load Balancing and proxy services are vital for container applications. They are built on the microservices architecture. Container load balancing aids in delivery traffic management services for container apps smoothly.

Follow this post to show you How To Install and Use Docker Engine on Debian 11 Tutorial.

Install and Use Docker Engine on Debian 11

Prerequisites

  • A server running Debian 11 with SSH access.
  • A root user or a user with sudo privileges.

Add Docker Repository

By default, the latest version of Docker Engine is not available in the Debian default repository. So you will need to add the Docker CE repository to APT.

First, install the required dependencies using the following command:

				
					apt install curl gnupg2 wget -y
				
			

After installing all the dependencies, add the Docker CE GPG key and repository using the following command:

				
					curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian  $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
				
			

Once the repository is added, update the repository cache using the following command:

				
					apt update -y
				
			

Once the repository is updated, run the following command to install Docker CE on your server.

				
					apt install docker-ce docker-ce-cli containerd.io -y
				
			

Once the Docker Engine is installed, start the Docker service and enable it to start at system reboot:

				
					systemctl start docker
systemctl enable docker
				
			

Verify the Docker Installation

After the Docker installation, you can also check the status of Docker service with the following command:

				
					systemctl status docker
				
			

You should see the following output:

				
					● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-06-25 06:07:49 UTC; 24s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 2379 (dockerd)
      Tasks: 7
     Memory: 30.8M
        CPU: 396ms
     CGroup: /system.slice/docker.service
             └─2379 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jun 25 06:07:48 debian11 dockerd[2379]: time="2022-06-25T06:07:48.479002824Z" level=info msg="scheme \"unix\" not registered, fallback to def>
Jun 25 06:07:48 debian11 dockerd[2379]: time="2022-06-25T06:07:48.479203811Z" level=info msg="ccResolverWrapper: sending update to cc: {[{uni>
Jun 25 06:07:48 debian11 dockerd[2379]: time="2022-06-25T06:07:48.479392105Z" level=info msg="ClientConn switching balancer to \"pick_first\">
Jun 25 06:07:48 debian11 dockerd[2379]: time="2022-06-25T06:07:48.565482842Z" level=info msg="Loading containers: start."
Jun 25 06:07:48 debian11 dockerd[2379]: time="2022-06-25T06:07:48.806279764Z" level=info msg="Default bridge (docker0) is assigned with an IP>
Jun 25 06:07:48 debian11 dockerd[2379]: time="2022-06-25T06:07:48.926592156Z" level=info msg="Loading containers: done."
Jun 25 06:07:48 debian11 dockerd[2379]: time="2022-06-25T06:07:48.988304124Z" level=info msg="Docker daemon" commit=a89b842 graphdriver(s)=ov>
Jun 25 06:07:48 debian11 dockerd[2379]: time="2022-06-25T06:07:48.989392226Z" level=info msg="Daemon has completed initialization"
Jun 25 06:07:49 debian11 systemd[1]: Started Docker Application Container Engine.
Jun 25 06:07:49 debian11 dockerd[2379]: time="2022-06-25T06:07:49.046162892Z" level=info msg="API listen on /run/docker.sock"

				
			

To verify the Docker package information, run the following command:

				
					docker version
				
			

You should get the following output:

				
					Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:03:17 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:23 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

				
			

Create a Hello world Container Using Docker

At this point, Docker is installed and running. Now, its time to create and run a hello world container in a Docker environment. Run the following command to launch the hello world container:

				
					docker run hello-world
				
			

This command will download the hello world Docker image and start it as shown below:

				
					Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:13e367d31ae85359f42d637adf6da428f76d75dc9afeb3c21faea0d976f5c651
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

				
			

You can now verify the downloaded Docker image using the following command:

				
					docker images
				
			

You should see the hello world Docker image in the following output:

				
					REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   9 months ago   13.3kB
				
			

Interact with Docker Container

In this section of how To Install and Use Docker Engine on Debian 11, we will show you how to use Docker container. To search for any Docker image, use the following syntax:

				
					docker search image-name
				
			

For example, to search for an Centos image, run the following command:

				
					docker search centos
				
			

You will get a list of all Centos images in the following output:

				
					NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                                       The official build of CentOS.                   7205      [OK]       
centos/systemd                               systemd enabled base container.                 108                  [OK]
centos/mysql-57-centos7                      MySQL 5.7 SQL database server                   95                   
kasmweb/centos-7-desktop                     CentOS 7 desktop for Kasm Workspaces            21                   
centos/nginx-112-centos7                     Platform for running nginx 1.12 or building …   16                   
kasmweb/core-centos-7                        CentOS 7 base image for Kasm Workspaces         3                    
continuumio/centos5_gcc5_base                                                                3                    
couchbase/centos7-systemd                    centos7-systemd images with additional debug…   1                    [OK]
spack/centos7                                CentOS 7 with Spack preinstalled                1                    
bitnami/centos-extras-base                                                                   0                    
couchbase/centos-72-jenkins-core                                                             0                    
fnndsc/centos-python3                        Source for a slim Centos-based Python3 image…   0                    [OK]
bitnami/centos-base-buildpack                Centos base compilation image                   0                    [OK]
couchbase/centos-69-sdk-build                                                                0                    
couchbase/centos-70-sdk-build                                                                0                    
spack/centos-stream                                                                          0                    
couchbase/centos-72-java-sdk                                                                 0                    
starlingx/stx-centos                         StarlingX centos                                0                    
ibmcom/fhe-toolkit-centos-amd64              The IBM Fully Homomorphic Encryption (FHE) T…   0                    
ibmcom/fhe-toolkit-centos                    The IBM Fully Homomorphic Encryption (FHE) T…   0                    
apache/couchdbci-centos                      Apache CouchDB CI CentOS                        0                    
silintl/openldap                             OpenLDAP base image on Centos 6                 0                    [OK]
datadog/centos-i386                                                                          0                    
spack/centos6                                CentOS 6 with Spack preinstalled                0                    
couchbase/centos-69-sdk-nodevtoolset-build                                                   0                    

				
			

From the above list, download the Centos image using the following command:

				
					docker pull centos:latest
				
			

This will download the Centos image from the Docker Hub registry:

				
					latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

				
			

You can verify the downloaded image using the following command:

				
					docker images
				
			

You will get the following output:

				
					REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   9 months ago   13.3kB
centos        latest    5d0da3dc9764   9 months ago   231MB
				
			

To create container from the downloaded Centos image, run the following command:

				
					docker run -it centos
				
			

This will create a container from the Centos image and connect to the container shell as shown below:

				
					[root@71581505c036 /]# 
				
			

Here, you can install any package inside the Centos container. Now, run the following command to exit from the Centos container:

				
					exit
				
			

To create a create a container from the Centos image and start it in background, run the following command:

				
					docker run -dit centos
				
			

You can now verify the running container using the following command:

				
					docker ps
				
			

You should see the running container in the following output:

				
					CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
ba772a1b4be2   centos    "/bin/bash"   7 seconds ago   Up 6 seconds             practical_bhaskara
				
			

Manage Docker Container

In this section, we will show you how to manage Docker container. You can start, stop or pause the Docker container using the following syntax:

				
					docker start/stop/pause container-id
				
			

For example, to start the Centos container, run the following command:

				
					docker start ba772a1b4be2
				
			

To stop the Centos container, run the following command:

				
					docker stop ba772a1b4be2
				
			

To pause the Centos container, run the following command:

				
					docker pause ba772a1b4be2
				
			

To remove the stopped container, run the following command:

				
					docker container rm ba772a1b4be2
				
			

If you want to stop all running containers, run the following command:

				
					docker container stop $(docker container ls -aq)
				
			

If you want to remove all stopped containers, run the following command:

				
					docker container rm $(docker container ls -aq)
				
			

To remove the unused Docker images and containers, run the following command:

				
					docker system prune -a
				
			

Great effort! We have learned How To Install and Use Docker Engine on Debian 11 Tutorial. Let’s summarize. 

How To Install and Use Docker Engine on Debian 11 Conclusion

In this post we showed you how to install Docker Engine on Debian 11 server. We also explained how to interact with Docker with different commands. I hope this guide will be useful to manage the Docker container. Docker is one of the best platform that changed the way software development used to be. It provides tremendous economies of scale and makes development scalable and simply user friendly.

A container provides orchestration across multiple public and private clouds, to simplify your environments and improve business performance and operational performance. It is vital part of hybrid cloud strategy that optimizes and modernizes your IT environment.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x