How To Install Docker Engine on Debian 11

0

Docker is an open-source software to easily create and run applications in an isolated environment called containers from any application. It provides an efficient way to package applications with their libraries and other dependencies into a standardized unit for software development.

Docker containers are much faster and more efficient than a virtual machine because they don’t have to run an entire operating system, just the executable that serves the application.

Here, we will see how to install Docker Comunity Edition (CE) on Debian 11.

Note: Docker requires a 64-bit version of Debian OS.

Install Docker on Debian 11

Remove Old Versions

First, uninstall the older versions of Docker packages called docker or docker-engine, along with dependencies from your system. However, this uninstallation would not remove existing Docker volumes, images, and networks found under the /var/lib/docker/ directory.

sudo apt remove -y docker docker-engine docker.io containerd runc

Setup Docker Repository

Install the below packages to let apt have the support of the HTTPS method.

sudo apt update

sudo apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common

Add the Docker’s GPG key to your system.

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Add the Docker repository to the system by running the below command.

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Update the repository index.

sudo apt update

Install Docker Engine

Install Docker Engine using the apt command.

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

Check the Docker version post the installation.

docker -v

Output:

Docker version 20.10.8, build 3967b7d

By now, the Docker service should be up and running.

sudo systemctl status docker

Output:

 docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-08-21 12:31:37 CDT; 1min 39s ago
TriggeredBy:  docker.socket
       Docs: https://docs.docker.com
   Main PID: 18894 (dockerd)
      Tasks: 8
     Memory: 31.3M
        CPU: 448ms
     CGroup: /system.slice/docker.service
             └─18894 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Aug 21 12:31:37 debian11.itzgeek.local dockerd[18894]: time="2021-08-21T12:31:37.192715381-05:00" level=info msg="scheme \"unix\" not registered, fallback to default s>
Aug 21 12:31:37 debian11.itzgeek.local dockerd[18894]: time="2021-08-21T12:31:37.192736530-05:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///r>
Aug 21 12:31:37 debian11.itzgeek.local dockerd[18894]: time="2021-08-21T12:31:37.192749042-05:00" level=info msg="ClientConn switching balancer to \"pick_first\"" modu>
Aug 21 12:31:37 debian11.itzgeek.local dockerd[18894]: time="2021-08-21T12:31:37.429344966-05:00" level=info msg="Loading containers: start."

Verify Docker Installation

To test the Docker installation, we will run the hello-world container.

sudo docker run hello-world

The below output confirms that you have installed Docker Engine correctly on Debian OS.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
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/

Allow Non-root users to run Docker Commands

By default, regular users do not have privileges to run Docker commands because the Docker daemon uses a Unix socket owned by the user root.

docker run hello-world

Output:

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.

To allow regular Linux users to run Docker containers without prefixing sudo, follow the below steps.

Create a group called docker if it does not exist.

sudo groupadd docker

Create a user if required. Replace itzgeek with your username.

sudo useradd -m -s /bin/bash itzgeek

Add the user to the docker group.

sudo usermod -aG docker itzgeek

Log out and log in back and then run Docker commands without prefixing sudo.

docker run hello-world

Interested Topics

Docker Basic Topics

1: Top Important Docker Commands – Working with Docker Containers

2: Working with Docker Images – Building Docker Images

3: How to Build Docker Images with DockerFile

Docker Advanced Topics

1: How to Setup Docker Private Registry on CentOS 7

2: How to Install and Configure Docker Swarm on CentOS 7

Conclusion

That’s All. I hope you have learned how to install Docker Engine on Debian 11.

You might also like