How to Install Docker on Debian 11

how to install docker on debian 11

Docker is a free and open-source platform to develop, and run applications in the containerized environment. It allows you to separate your application from your infrastructure. This will make it easier, simpler, and safer to build, deploy and manage containers. Docker is designed to set up a local development environment.

In this tutorial, we’ll learn how to install Docker on Debian 11.

Prerequisites:

  • A Debian 11 server.
  • A root user or a user with root privileges.

Updating the system

Before we start installing everything, we should upgrade our system, so after logging in as root, you can run:

apt-get update -y
apt-get upgrade -y

Installing dependencies

Also, it’s required by Docker some dependencies, so you can easily install them with this command:

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

Adding the Docker Repository

  1. Since our dependecies are installed, we’ll proceed with adding the Docker Repository so we can fetch our download, first of all run the following command to add the GPG Key:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  1. Then, we’ll add the docker repository using this 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
  1. You should now run a new update & upgrade on your system to update everything:
apt-get update -y
apt-get upgrade -y

Now, we are ready to install Docker.

Installing docker

  1. If you have had Docker installed previously on your system from the Debian repository, you should run the following to remove the services, if you don’t, you can skip to step 2:
sudo apt remove docker docker-engine docker.io containerd runc
  1. Now we can finally run our Docker installation with this command:
apt install docker-ce docker-ce-cli containerd.io -y
  1. When your installation complete, you can verify the docker service with the following commands:
systemctl is-enabled docker
systemctl is-enabled containerd

Also, you can check the status of your server with a simple command:

systemctl status docker containerd

And we are done. You have successfully installed Docker on your Debian 11. If you need to allow a non-root user to run Docker containers, you can follow the optional steps below.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

Optional steps (Allowing Non-root user to use Docker)

Docker only accepts root user by default, but in this step we’ll enable a non-root user to be able to run containers on it. You need to add your non-root user to the ‘docker’ group.

  1. In this example we will use a test user called “robert” to run the docker container.

Create the new user ‘robert’ on our Debian System using the following command:

useradd -m -s /bin/bash -G docker robert

With the above command, our user will be created and assigned to the docker group.

We can now check by accessing the user with this below command:

su - robert

And then we’ll run the hello world docker

docker run hello-world

Congratulations. You successfully installed and configured the Docker server on your Debian 11 VPS. Also, you learned how to configure a non-root user to run docker containers.

Of course, you don’t have to install Docker on Debian 11, if you use one of our NVMe VPS Hosting plans, in which case you can simply ask our expert Linux admins to install Docker on Debian 11 for you. They are available 24×7 and will take care of your request immediately.

Leave a Comment