Art, Programming, Linux

Andrew's notes

Home Posts Tags

Installing Docker on Debian 11: A Step-by-Step Guide

Following the official documentation on how to install Docker on Debian

Published on February 13, 2023 645 words 4 min read Linux

Image by Frank Mckenna

Docker is a powerful tool for running containers, and its installation process can sometimes be confusing, especially if you are new to the technology. In this article, we will be guiding you through the process of installing Docker on Debian 11, making it easy to follow along and get it up and running in no time.

Please note that the installation process of Docker has already been covered in great detail in the official Docker documentation. However, the information can be scattered across multiple pages, making it challenging to follow. This article aims to consolidate all the necessary steps in one place to help you with the installation process.

I won’t be explaining the purpose or functionality of the various technologies used during the installation of Docker as this article is focused on the installation process itself. Let’s dive in and get started with the installation process.

The entire process for a clean installation as recommended by the folks over at Docker can be summarized in three steps:

  • Pre-setup and Cleanup
  • Download the latest version
  • Setup

Step 1 - Pre-setup and Cleanup #


First things first, update and upgrade.

sudo apt update -y && sudo apt upgrade -y

We need to load KVM modules

$ sudo modprobe kvm

$ sudo modprobe kvm_intel  # intel processors
$ sudo modprobe kvm_amd # amd processors

Check who owns /dev/kvm:

$ ls -al /dev/kvm 
crw-rw----+ 1 root kvm 10, 232 Apr  8 06:11 /dev/kvm

Add your user to the KVM group and reboot:

$ sudo usermod -aG kvm $USER

$ sudo reboot

Then we can remove any previous version of docker-desktop along with any previous configuration, symlinks and data files. Ignore this step if you are installing docker for the first time.

$ rm -r $HOME/.docker/desktop

$ sudo rm /usr/local/bin/com.docker.cli

$ sudo apt purge docker-desktop

Step 2 - Download and install Docker #


Install dependencies:

$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Add Docker’s official GPG key:

$ sudo mkdir -m 0755 -p /etc/apt/keyrings

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

If you are using a firewall which blocks most requests like myself you might find that curl was blocked. Config your firewall to allow curl if you run into an error at this stage.

Use the following command to setup the repository:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

At this stage take a moment to download the latest deb package from their website. When the download is done proceed.

Step 3 - Setup #


$ sudo apt-get update

$ sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

$ sudo apt-get install ./docker-desktop-<version>-<arch>.deb

It will take a while for the installation to complete, hopefully with no errors. Once it is done run the following command:

systemctl --user start docker-desktop

Immediately you will be greeted with docker’s interface. Remember to configure your firewall to allow docker and its processes otherwise it will be stuck at this stage, unable to start or stop properly.

To enable docker to start on boot:

systemctl --user enable docker-desktop

Check that docker is running properly. The commands should return no errors.

$ docker compose version

$ docker --version

$ docker version

Done ! Docker should be installed properly and using the docker run -d -p 80:80 docker/getting-started command in a terminal should work.

Dockerhub Login #

To login, first we need to create a gpg-key and then use pass with our public key. You will be prompted for a password when generating your key. Do not forget this password as you might be prompted by docker to enter this password when the application starts.

$ gpg --full-generate-key

$ pass init <generated gpg-id public key here without the brackets>

If you completed the above steps correctly you will be able to login normally in Docker Desktop. Congrats !

---

If you found this post useful please consider donating a small amount to support my effort in creating more content like this.