How To Install Docker in Debian: Complete Guide

How To Install Docker in Debian: Complete Guide

Are you curious about enhancing your Debian system? Docker Engine, an indispensable tool for running containerized applications, is the solution. Docker not only streamlines your workflow but also boosts efficiency.

This makes Docker a must-have for any server, particularly those running Debian. The installation process, however, can be a bit challenging, especially for novices. But don’t fret, we’re here to help!

In this blog post, we aim to demystify the process for you. We provide a comprehensive, step-by-step guide on installing Docker Engine on Debian. We’ll guide you through managing prerequisites, uninstalling older versions, and exploring different installation methodologies.

So, get ready for an immersive journey into the Docker and Debian universe!

TL;DR: How do I install Docker Engine on Debian?

To install Docker Engine on Debian, ensure your system meets the prerequisites, uninstall any old Docker versions, and choose an installation method (using the apt repository, manual installation, or installing from a package). For more advanced methods, background, tips, and tricks, continue reading this article.

Basic Installation Example:

# Update your repository
sudo apt-get update

# Uninstall older versions of Docker
sudo apt-get remove docker docker-engine containerd runc

# Install Docker Engine
sudo apt-get install docker-ce docker-ce-cli

Prerequisites and Requirements

Before diving into the installation process, it’s paramount to comprehend the prerequisites and the operating system requirements for installing Docker Engine on Debian. Let’s dissect each one.

Docker Installation Prerequisites

Firstly, your system must meet specific prerequisites. Docker Engine is compatible with a variety of Debian versions. Nonetheless, it’s always advisable to use the latest stable Debian version to ensure compatibility and get the most recent security updates.

Firewall Settings

A crucial one is addressing potential firewall settings issues. Docker relies on a range of ports to function optimally, and if a firewall obstructs these ports, Docker might not perform as expected.

Hence, configuring your firewall settings to permit Docker’s essential ports is vital.

Example of configuring firewall settings:

# Allow Docker's essential ports
sudo ufw allow 2375/tcp
sudo ufw allow 2376/tcp
sudo ufw reload

Uninstalling Old Docker Versions

Before installing Docker Engine, it’s important to uninstall any old versions or conflicting packages. These can create conflicts and hinder Docker Engine from installing or functioning correctly.

Therefore, if you have any older Docker packages installed, it’s time to remove them:

sudo apt-get remove docker docker-engine containerd runc

Running Docker Without Sudo

Interestingly, Docker can be configured to run without sudo. By creating a docker group and adding your user to this group, you can enhance convenience and bolster the security of your system.

Example of creating a docker group and adding your user to this group:

# Create the docker group
sudo groupadd docker

# Add your user to the docker group
sudo usermod -aG docker $USER

Installation Methods

Docker Engine on Debian can be installed in a variety of ways, with the choice largely depending on your specific needs and preferences.

Primarily, Docker Engine can be installed in three ways:

  1. Using the apt repository
  2. Manual installation
  3. From a package

Let’s delve into each of these methods.

Installing Docker Engine Using the apt Repository

The apt repository is a handy method to install Docker Engine. This process involves adding Docker’s official GPG key and setting up the stable repository.

After this setup, Docker Engine can be installed with a few quick commands. This method is simple and recommended for the majority of users.

Example of installing Docker Engine using the apt repository:

# Add Docker's official GPG key
curl -fsSL | sudo apt-key add -

# Set up the stable repository
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

# Update the apt package index
sudo apt-get update

# Install Docker Engine
sudo apt-get install docker-ce docker-ce-cli

Manual Installation

If you want more control over the installation process, a manual installation might be your preference. This method requires directly downloading the Docker package and installing it manually.

Although manual installation offers more control, it’s a bit more complex and necessitates a good understanding of Linux commands.

Example of manual Docker installation:

# Download the Docker package
wget$(lsb_release -cs)/pool/stable/amd64/docker-ce_20.10.7~3-0~ubuntu-$(lsb_release -cs)_amd64.deb

# Install Docker manually
sudo dpkg -i docker-ce_20.10.7~3-0~ubuntu-$(lsb_release -cs)_amd64.deb

Installing Docker Engine from a Package

Alternatively, Docker Engine can be installed from a package. This involves downloading a .deb package and installing it using the dpkg command.

Installing from a package is ideal if you wish to install a specific Docker version.

Example of installing Docker Engine from a package:

# Download the .deb package
wget$(lsb_release -cs)/pool/stable/amd64/docker-ce_20.10.7~3-0~ubuntu-$(lsb_release -cs)_amd64.deb

# Install Docker using the dpkg command
sudo dpkg -i docker-ce_20.10.7~3-0~ubuntu-$(lsb_release -cs)_amd64.deb

Docker Repositories vs Debian Repositories

For the most recent Docker version and smooth upgrades, it’s recommended to install Docker from Docker repositories rather than Debian repositories.

Docker repositories always house the latest Docker version, whereas Debian repositories might not be as up-to-date.

SourceLatest Docker VersionSmooth Upgrades
Docker RepositoriesYesYes
Debian RepositoriesNoNo

Convenience Script Installation

While the apt repository, manual installation, and package installation methods are common, there’s another method that’s worth discussing – the convenience script. This method is fast and simple, but it comes with its own set of risks and limitations.

Convenience Script for Docker Installation

A convenience script is a Docker-provided script that automates the installation process. It’s named a ‘convenience’ script as it simplifies the installation process to a single command. However, convenience comes with risks.

The convenience script automatically executes several operations on your system, including adding Docker’s official GPG key, setting up the stable repository, and installing Docker.

While this is handy, it also implies that the script has full control over these operations. Hence, it’s of utmost importance to use convenience scripts only from trusted sources.

How To Use the Convenience Script

To use the convenience script for Docker installation, you simply need to download the script and execute it. This will automatically carry out all the necessary steps to install Docker on your system.

Example of using the convenience script for Docker installation:

curl -fsSL -o
sudo sh

Here’s how you can do it:

curl -fsSL -o
sudo sh

Installing Pre-releases Using the Convenience Script

The convenience script can also be used to install pre-releases of Docker. This is beneficial if you’re eager to test the latest Docker features before they’re officially released.

Bear in mind that pre-releases may not be as stable as the official releases.

Example of installing pre-releases using the convenience script:

curl -fsSL -o
sudo sh

Risks and Limitations of Convenience Scripts

While convenience scripts are indeed convenient, they’re not recommended for production environments. This is due to their automatic execution of numerous operations on your system, potentially introducing security risks.

Moreover, if something goes awry during the installation process, troubleshooting can be challenging because the script performs many operations automatically.

Convenience Scripts in Testing and Development Environments

Despite their risks and limitations, convenience scripts play a crucial role in testing and development environments. They enable developers to quickly set up Docker and test their applications, thereby accelerating the development process.

However, for production environments, it’s advisable to use more secure installation methods like the apt repository, manual installation, or package installation.

Each installation method has its advantages and disadvantages, and the choice depends on your specific requirements and level of expertise. By selecting the right installation method and understanding Docker’s features, you can significantly enhance your Docker experience.

Uninstalling Docker Engine

Having covered the installation process, it’s time to discuss how to uninstall Docker Engine and the steps to take after installing Docker.

There might be instances when you need to uninstall Docker Engine from your Debian system. This could be due to a variety of reasons – perhaps you wish to install a different version, or maybe Docker is causing issues on your system.

Regardless of the reason, it’s crucial to understand the correct steps to uninstall Docker Engine and its associated packages.

To uninstall Docker Engine, use the following commands:

# Uninstall Docker Engine
sudo apt-get purge docker-ce docker-ce-cli

# Remove all images, containers, and volumes
sudo rm -rf /var/lib/docker

The first command uninstalls the Docker packages, and the second command removes all images, containers, and volumes.

Cleaning Up After Uninstallation

When you uninstall Docker, it’s also advisable to delete all images, containers, and volumes.

These can occupy a significant amount of space on your system, and leaving them behind can lead to clutter and potential issues in the future.

To delete all images, containers, and volumes, use the prune command:

# Remove all unused data
docker system prune -a

This command will remove all unused data, freeing up space on your system.

Don’t “prune all” unless you are sure you want to delete all docker images and settings!


In this detailed guide, we’ve explored every aspect of installing Docker Engine on Debian. We began by understanding the prerequisites, including the operating system requirements and the significance of uninstalling any old Docker versions. We also explored the option of running Docker without sudo.

We then investigated various installation methods, including using the apt repository, manual installation, and installing from a package. We also emphasized the benefits of using Docker repositories over Debian repositories for the most recent Docker version and easy upgrades.

Further, we ventured to understand the convenience scripts and their role in Docker installation, particularly in testing and development environments. While discussing their convenience, we also examined the potential risks and why they are not recommended for production environments.

Lastly, we discussed how to uninstall Docker Engine and the importance of deleting all images, containers, and volumes.

Docker’s containerization is a revolutionary change, enhancing application deployment consistency across different platforms. By understanding how to correctly install Docker Engine on Debian, you’re one step closer to harnessing the full power of Docker. So, take the plunge into the world of Docker, and enjoy containerizing!