Home » Install Docker on Debian 11

Install Docker on Debian 11

In this procedure, I will explain how to install Docker on a Debian 11 machine. Installing Docker on a Debian virtual machine allows to keep the use of virtual machines and containers simultaneously. Docker is a virtualization tool, easy to use and very light. Moreover Docker has the advantage to keep the same environment for development and production. Docker will use only the performance it needs, and then it will bridge the machine that hosts it to choose the ports and volumes it will use.

Logo Docker

Prerequisites to install Docker on Debian 11:

  • A Debian machine
  • A root access on the machine

Install Docker on Debian 11:

To begin the installation of docker on Debian, we will start with an update of the machine :

apt update

Then the installation of the dependencies:

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

Then, we add the official GPG key of Docker :

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

Adding the Docker repository in the sources :

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" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Then we update the list of sources:

apt update 

Then, we download the Docker package from the :

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

Finally we check the installation of Docker on the machine:

docker run hello-world

If you get the same results as below, the installation of Docker is successful on your machine:

Install docker on Debian 11 - Docker run hello-world

Source :

https://docs.docker.com/

Recommendations for using Docker :

If you have never used Docker, you can use Portainer which is a graphical interface to manage containers.

Some useful commands to use Docker :

systemctl start/stop docker          # Start/stop docker service
systemctl enable docker              # Activate docker at system startup
docker pull                          # Download a Docker image 
docker ps                            # List all active Containers
docker ps -a                         # List all Containers 
docker start/stop CONTAINER ID       # Start/Stop Container   
docker rm CONTAINER ID               # Delete Container by ID
docker kill CONTAINER ID             # Shutting down a container by ID
docker images                        # List all the Docker images that have been downloaded

The commands are also on the official site of Docker: https://docs.docker.com/.
Docker is widely used to host applications because it allows to emulate a machine with dependencies (used by developers).
Don’t forget to secure your Docker server with Fail2ban and a Firewall like UFW (UFW Firewall on Debian 11).

You may be interested in :