Install Latest Docker on Debian Linux

Docker is available in the default repository of Debian but by its nature, you are bound to get old docker versions.

However, if you don't care about having the most recent versions, you can use the given command and docker will be installed on your Debian system:

sudo apt install docker.io

But if you are looking for a way to get the most recent images, you must utilize the official repository to install docker.

Before jumping to the installation part, it is necessary to remove the older version of Docker:

sudo apt-get remove docker docker-engine docker.io containerd runc

And this tutorial is all about how you can install docker using the official repository.

Installing the latest Docker in Debian

First, you have to install the following packages so you can use HTTPS over the apt repository:

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

Next, you have to use the following command to create /etc/apt/keyrings if it does not exist by default:

sudo mkdir -p /etc/apt/keyrings

Adding GPG Keys

GPG keys are used to authenticate the packages to verify the source of the package.

And to add the GPG key for docker, the following command should get the job done:

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

Adding the official Docker repository

The repository is where the packages are stored and to add a docker repository in Debian, utilize the given command:

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

Installing Docker in Debian

First, you have to update the repository index to take effect from the changes you've just made:

sudo apt update

Now, you can use the given command to install the most recent version of docker:

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

Running Hello World image in Docker

To check for successful installation of docker, you can use the hello-world image:

sudo docker run hello-world

And it will download a hello-world image, greet you, and will exit by itself:

And you have it.

But if you haven't noticed, it requires sudo (superuser privileges) to work with docker images. Don't want to use sudo with Docker commands all the time? Next section solves your problem.

Using Docker without sudo in Debian

The first step is to create a new user group named docker:

sudo groupadd docker

Now, you can add the user to the docker user group with the usermod command:

sudo usermod -aG docker <username>

Remember, the changes will only be applicable to the added user so you can add multiple users too!

⚠️
You should only add the user who is having superuser privileges.

And if your current user does not have superuser privileges, we have a detailed guide on how you can add users to the sudoers file.

Now, log out and log back in to re-evaluate the group membership. And if you are using VM, a reboot is necessary.

Once done, you can use the given command to activate the changes:

newgrp docker

And now, you can use docker images without sudo:

Wrapping Up

In this tutorial, I explained how you can install docker in Debian using two methods including how you can avoid using sudo every time working with docker.

I hope you will find this guide helpful and if you have any queries, let me know in the comments and I will try my level best to solve your problem.