How To Install Docker on Debian

October 28, 2019

Introduction

Docker is a platform for creating, deploying, and managing self-contained software units called containers. By virtualizing the underlying operating system, Docker isolates containers from the rest of the host while allowing inter-container communication.

In this tutorial, you will learn how to install Docker on Debian.

Tutorial on how to install Docker on Debian.

Prerequisites

  • Debian installed.
  • Command-line access.
  • A user account with sudo privileges.

Install Docker on Debian

The most efficient method for installing Docker on Debian is utilizing the official distribution repositories. For the most up-to-date packages, using the official Docker repository is recommended.

Additionally, it is possible to install Docker manually by downloading the necessary DEB packages. This method is convenient for users with air-gapped systems and no access to the Internet.

The following sections present all three methods for installing Docker on Debian.

Note: If you run the Raspbian OS on Raspberry Pi, the only way to set up Docker is by using automated convenience scripts. For more information, read Docker on Raspberry Pi - Installation Guide.

Method 1: Install Docker Using Debian Repositories

The official Debian repositories contain recent Docker packages that are available for installation via the APT package manager. To ensure the packages are up-to-date:

1. Refresh the repository package list:

sudo apt update

2. Install Docker by entering the following:

sudo apt install docker.io

3. Type Y and press Enter when prompted to start the installation.

Installing Docker from the Debian repositories.

Method 2: Install Docker Using Official Docker Repository

Installing Docker from the official Docker repository ensures access to the latest stable version of the platform. Follow the steps below to install Docker on a Debian-based system:

1. Refresh the package list:

sudo apt update

2. Download the tools that enable adding the Docker's official GPG key over HTTPS:

sudo apt install ca-certificates curl

3. Create the keyrings directory with sufficient permissions:

sudo install -m 0755 -d /etc/apt/keyrings

4. Download the GPG key and place it in the directory created in the previous step:

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

5. Change permissions for the keyring:

sudo chmod a+r /etc/apt/keyrings/docker.asc

6. Add the signed Docker repository to the list of sources on the system:

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

7. Refresh the package list again:

sudo apt update

The Docker repository appears in the output.

The official Docker repository among the sources updated with the apt update command.

8. Install the Docker packages by typing the following command:

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

Note: The docker-buildx-plugin and docker-compose-plugin packages are optional.

Enter Y to start the installation.

Installing Docker and the related packages from the official Docker repository.

Method 3: Install Docker Manually on Debian

Users who cannot install Docker from repositories can set it up manually via DEB packages. Proceed with the steps below to download and install Docker using this method:

1. Navigate to the Debian distributions section on Docker's official website.

2. Select the relevant version of Debian. The latest stable release is at the top of the list.

The contents of the linux/debian/dists directory on Docker's official website.

3. Navigate to pool>stable and select the desired architecture.

The contents of the linux/debian/dists/bookworm/pool/stable directory on Docker's official website.

The list of available packages appears.

4. Download the latest versions of the containerd.io, docker-ce-cli, and docker-ce packages.

5. Go to the directory with the downloaded files and install packages using the dpkg command. The examples below use the latest packages at the time of writing the article:

sudo dpkg -i containerd.io_1.7.22-1_amd64.deb
sudo dpkg -i docker-ce-cli_23.0.0-1~debian.12~bookworm_amd64.deb
sudo dpkg -i docker-ce_23.0.0-1~debian.12~bookworm_amd64.deb

Verify Docker Installation on Debian

After installing Docker, check the platform version:

docker --version
The installed Docker version in the output of the docker --version command.

Using the docker run command, create and start a hello-world test container to ensure the container service has been configured correctly:

docker run hello-world

The command automatically downloads the hello-world image, creates a container based on it, and starts the container. The output confirms that the installation is working correctly.

The output of the hello-world Docker container.

Note: If you encounter the Permission Denied error, read How to Fix Docker Permission Denied.

Uninstall Docker from Debian

Once you do not need Docker on your system, uninstall it with the following apt command:

sudo apt purge [installed-docker-package]

For example, to uninstall docker-ce, type:

sudo apt purge docker-ce
Uninstalling docker with apt purge.

The command deletes the docker-ce package. However, any additional files related to it, such as images, containers, and custom configuration files, remain on the system. Remove everything, including the Docker directory, with the rm command below:

sudo rm -rf /var/lib/docker

Conclusion

After following the steps of this article, you installed Docker on Debian, verified the installation, and learned how to remove Docker once it is no longer necessary.

If this is your first time working with Docker containers, read how to list, start, and stop Docker containers to get started.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How to List / Start / Stop Docker Containers
October 28, 2019

A Docker container uses an image of a preconfigured operating system environment. Images are often...
Read more
How to Share Data Between Docker Containers
March 26, 2019

Docker allows users to run applications isolated from a host computer, without the necessity of having...
Read more
How To Remove Docker Images, Containers, Networks & Volumes
February 7, 2019

Docker allows users to create a container in which an application or process can run. In this guide, you will...
Read more
How to Manage Docker Containers? Best Practices
January 29, 2019

With Docker Container Management you can manage complex tasks with few resources. Learn the best practices of...
Read more