18.6 C
Texas
angeloma
Senior Writer and partner

Install Docker on Debian 11

Hello, friends. With Debian 11 up and running, the upgrade work that many sysadmins do begins. Part of it involves installing Docker on Debian 11 so they can deploy their images again without problems on this new system.

For those of you who don’t know, Docker is a not-so-old technology for creating and deploying applications using containers. Containers allow you to package an application with all the parts you need, such as libraries and other dependencies and deploy it as a single package.

One of the advantages of using containers is that we can be sure that our application will run the same on other computers and systems that support Docker regardless of any custom configuration the machine may have.

So, as you can see, developers and sysadmin consider Docker essential to do most of the work they do.

- Advertisement -

So, let’s install it on Debian 11.

Install Docker on Debian 11

From the official Docker documentation, we are told that there are several methods of installation. One of them is to add the official Docker repository to the system to get the latest stable version available. This is the recommended method.

So, connect via SSH to your server or open your terminal and make sure the system is up to date.

sudo apt update
sudo apt upgrade

In case you don’t have sudo access then you will have to run these commands as root.

If you want to install Docker on your system, you probably don’t have it, but you want to make sure it is not installed. This is especially important in work environments where access is shared.

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

Next, install a few packages needed to complete the tutorial.

sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

After this, add the GPG key from the repository.

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

And now yes, add the Docker repository for Debian 11

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 > /dev/null

Refresh APT again and now install Docker on the system.

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
Recommended packages:
  apparmor docker-ce-rootless-extras git libltdl7 pigz docker-scan-plugin
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli
0 upgraded, 3 newly installed, 0 to remove and 2 not upgraded.
Need to get 84.7 MB of archives.

Now you can verify the installed version with the command

docker --version
Docker version 20.10.8, build 3967b7d

And also check the status of the service

sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-09-07 17:34:04 CEST; 2min 47s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 3127 (dockerd)
      Tasks: 8
     Memory: 38.1M
        CPU: 318ms
     CGroup: /system.slice/docker.service
             └─3127 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.207590098+02:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=gr>Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.207613182+02:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/co>Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.207627959+02:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.291431722+02:00" level=info msg="Loading containers: start."
Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.507218484+02:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16>Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.586246350+02:00" level=info msg="Loading containers: done."
Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.607084077+02:00" level=info msg="Docker daemon" commit=75249d8 graphdriver(s)=overlay2 version=20.10.8 Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.607211307+02:00" level=info msg="Daemon has completed initialization"
Sep 07 17:34:04 osradar systemd[1]: Started Docker Application Container Engine.
Sep 07 17:34:04 osradar dockerd[3127]: time="2021-09-07T17:34:04.638456943+02:00" level=info msg="API listen on /run/docker.sock"

Configuring Docker before using it

By default, Docker is used with the root user. This can lead to security problems and you may not want to do it.

So to be able to use Docker without being root, you need to create a group called docker and add your user to this group.

sudo groupadd docker
sudo usermod -aG docker $USER

Log out and log back in so that your group membership is re-evaluated.

This is enough.

Another thing you can do is to make Docker start with the system. To do this, run these commands.

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

Now we can test the installation.

Testing Docker on Debian 11

To test Docker, just run the hello-world image that is included in the installation.

docker run hello-world
1.- Docker running on Debian 11
1.- Docker running on Debian 11

The image indicates that everything went well. Enjoy it.

Conclusion

Docker is a fantastic tool that has revolutionized the way software is distributed. For this, it is necessary to install it on a robust system like Debian 11.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article