How to Install Docker in Debian?

Photo of author

By admin

If you have been into coding for long – or even for so, chances are pretty high that you may already know what Docker is, and how the platform makes it easier for developers to build, manage, and deploy containers. You probably might have some experience with it.

But if you still haven’t used the leading containerization platform yet, and are looking to use it on Debian, then you are at the right place.

Here in this article, we are offering you a step-by-step guide on how to install Docker in Debian. But before coming to that, let’s first get a brief introduction to Docker.

What is Docker?

Docker is one of the most renowned platforms that simplifies the workflow of managing application processes within containers. It enables your application to run in resource-isolated environments. Although Docker containers are similar to that of virtual environments, they are known to be superior in terms of resource-usage and portability.

Now, let’s discuss how to install Docker in Debian. In addition to learning how to install Docker, you will learn how to uninstall any previous versions of the same as well. So, let’s start with the requirements first.

Prerequisites

OS

The docker engine can be currently installed on the 64-bit versions of Debian or Raspbian (Debian optimized for Raspberry Pi hardware) distributions.

  • Debian Buster 109stable)
  • Debian 9/ Raspbian (Stretch)

Docker Hub Account (Optional)

In case you want to create your own Docker images and push them directly, you need to create an account on Docker Hub.

Installation Methods for Docker

There are 3 ways in which you can install the Docker Engine. Based on your requirement, you can pick an installation process among these:

  1. Installation via Repository – Repositories are the easiest to install and preferred by a vast majority of the users. Since this process is easy to install and upgrade, it is the most recommended approach.
  2. Installation from the Package – Downloading the DEB package and installing it manually is another way to go. While you have to manage the upgrades manually, you can still install Docker on systems with restricted internet access.
  3. Installation via a Convenience Script – The convenience scripts are readily available to install Docker versions, testing and development environments as well.

1. Installing via Repository

Prior to installing the Docker Engine for the first time, you need to set up the repository. Later on, you can always update the Docker Engine from the repository.

Note: Installation using the repository is not supported for Raspbian distribution. Instead, look up for the convenience script.

Setting up the Repository

Step #01 – After you update the system, make sure to allow apt. Doing so will provide full control to the repository over HTTPS:

$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common

Step #02 – To add Docker’s official GPG key, use the following command:

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

The verification requires a key with a fingerprint. Type in the last 8 characters of the fingerprint.

$ sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
  Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid  Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22

Step #03 – Make sure to install the stable repository. To try out the other releases, you can replace stable with nightly or test:

$ sudo add-apt-repository \
 "deb [arch=amd64] https://download.docker.com/linux/debian \
 $(lsb_release -cs) \
 Stable"

Install the Docker Engine

After updating the package index, you can install the latest version of the Docker Engine using the following command:

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Upgrading Docker

After installing the Docker Engine from the repository, you can always upgrade using the sudo apt-get update command.

2. Install from the Package

It is not always possible to install Docker Engine using the repository. On the contrary, you can always download the corresponding .deb file and then, manually install the same. Just make sure to update the package manually every single time.

Step #01 – Go to https://download.docker.com/linux/debian/dists/. and choose a Debian version that you wish to install.

Step #02 – After that, browse to pool/stable/ and search for amd64, armhf, or arm64.

Step #03 – Download the corresponding .deb file.

Step #04 – To install a test package, you need to replace the word stable with test. After downloading the Docker Engine, you need to install it. You can easily install it by changing the following path to the path to your download directory:

$ sudo dpkg -i /path/to/package.deb

The progress will begin with the Docker Daemon tool.

Step #05 – Run the hello-world image to properly verify if Docker is correctly installed or not by using:

$ sudo docker run hello-world

Now you can download the test image to run within the container. In the meantime, it will print a message with some vital pieces of information and then exit.

Now, your Docker engine has been installed and a new Docker group is created with no users added to it. In order to run docker commands, you need to be an admin.

Upgrading the Docker Engine

You need to download the latest package and repeat the installation procedure in order to upgrade the docker engine.

3. Installing via a Convenient Script

Installing the Docker Engine via convenient scripts is another great way to get Docker up and running. The Conventional Scripts are readily available at get.docker.com and test.docker.com. You can install edge and testing versions quickly with it. You can find the source code within the docker-install repository.

CAUTION! Convenient scripts pose some serious issues if not taken into consideration beforehand. Here are some of the potential risks involved with running the Convenient Script:

  • You need to audit the scripts carefully before giving it sudo privileges.
  • The package management system will be configured by the script.
  • No room available for customizing the installation parameters.
  • You are going to end up installing the latest version.
  • If Docker is already installed on the host machine with another mechanism, don’t run the scripts.

You can use the script from get.docker.com and get the Docker-Engine community edition. To install the testing version, you need to install scripts from test.docker.com. All you need to do is to replace all get with tests.

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
<output truncated>

For all the non-root users, you can add them to the docker group with the following command:

sudo usermod -aG docker <your-user>

Note: You will start noticing the effects after successfully logging out.

You must need to test the script before running locally. Also, you must be careful while adding a user to the Docker group as it will allow her to run containers that can be used to gain root privileges.

Docker Engine is now installed and it will start on Deb-based distribution automatically. Start using the proper systemcl or service command for rpm-based distributions.

Upgrading the Docker Engine

After using the Docker Engine via a conventional script, you need to upgrade it directly via your package manager. Now, re-installing the conventional script will re-add repositories that are already added to the host machine.

How to Uninstall Docker Engine?

Want to know how to uninstall Docker from Debian? Here’s how:

Step #01 – Use the following command to uninstall the Docker Engine:

$ sudo apt-get purge docker-ce docker-ce-cli containerd.io

Step #02 – You have to delete all the images, containers and volumes manually. Any edited configuration file must be deleted manually as well. Use the below commands to do so.

$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd

The Bottom Line

It is comparatively easy to install Docker on a Debian distribution, especially on Debian 10. Why must you use Docker on Debian for managing/leveraging containers? Because it is the de facto leader of all container technologies.

Also, being an integral tool for all the DevOps engineers, Docker offers a seamless integration through the delivery pipeline. So, get started today and let us know your experience in the dedicated comments section below.

Leave a Comment