How to Install Docker on Debian 11

x


Debian 11 is one of the most widely used operating systems on servers. So, it is not surprising that we have to learn how to install Docker on Debian 11 if you are interested in server and sysadmin roles. You can also use this post as a first step to start playing with this technology.

So, before we start with the installation process, let’s give a brief introduction of what Docker is.

What is Docker?

Docker is a program that allows you to package software in containers and run them on top of virtual machines. These containers are completely independent which increases the security of the container. With Docker, we forget that our software works on one machine and not on others because of configuration problems.

Because these containers only carry what is necessary for the application to work, they are much lighter than virtual machines, and when we talk about capacity on our servers, that pays off in being able to place more applications with the same existing resources.

In addition to this, Docker is an open-source technology with great support for Linux and in its image repository, we can find many applications and systems.

So, let’s install it on Debian 11.

Install Docker on Debian 11

Assuming we are installing on a remote server, then you have to connect via SSH.

Once you are inside the server, you can update the whole package.

sudo apt update
sudo apt upgrade

With the system installed, you then need to install some packages needed to add the Docker repository to the system.

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

These packages are lightweight and installation should be almost immediate.

Now, with the help of the curl command, you have to add the GPG key from the Docker repository and we will add it to the system at once.

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

After this, you can then add the Docker repository with the following 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 > /dev/null

Next, refresh APT so that the repository is uploaded to the system

sudo apt update

Now, you can install Docker on Debian 11 as follows

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

When the installation is finished, you can check the Docker version with the following command

docker – version
Docker version 20.10.9, build c2ea9bc

Working with Docker service

Although Docker is an application for managing containers, it is also managed through a system service. In this case, to check the status of the service, you can run

sudo systemctl status docker

To stop the Docker service, you have to run

sudo systemctl stop docker

If you want to start it, then

sudo systemctl start docker

Or finally, you can restart it as follows

sudo systemctl restart docker

In either case, Docker is enabled to start with the system. If you want to change this behaviour

sudo systemctl disable docker

Or to start it with the system

sudo systemctl enable docker

That’s how easy it is to manage the Docker service.

Testing the Docker installation

Docker requires root privileges. In case you don’t want this, you can add the user to the docker group that was created during the installation.

sudo usermod -aG docker $USER

Then enable another Docker-associated service

sudo systemctl enable containerd.service

Then, refresh the SSH session and when you reopen it, you will be able to use Docker without being root.

In this case, to test if Docker has been correctly installed is by running the following command

docker run hello-world

If you get an output screen similar to this then Docker is fully installed and ready to use.

Docker on Debian 11
Docker on Debian 11

Removing Docker on Debian 11

If you want to uninstall Docker from the system, then in a terminal session, you have to run

sudo apt autoremove docker-ce docker-ce-cli containerd.io

Also, it is a good idea to remove the repository we have added to the system.

To do this, delete the file where the information is in the Docker repository.

sudo rm /etc/apt/sources.list.d/docker.list

and refresh APT to apply the changes.

sudo apt update

Conclusion

Docker is a current technology that helps the deployment of applications in the form of containers and images. This helps many sysadmin to deploy applications smoothly.

So, have you used Docker? do you like it? what is it like? So, help us grow and leave us a comment and of course share the post.