Install Docker on Debian 12

Learn how to install Docker on Debian 12 properly. Also learn to run Docker without sudo and remove it when not needed.
Warp Terminal

Want to use Docker on Debian 12? Let me help you with that.

Docker is available to install from the Debian repositories. All you have to do is to run this command:

sudo apt install

However, you will not get the latest Docker version from Debian.

This is why I recommend installing it from the Docker repositories itself. This way, you get the latest Docker version on Debian along with any future updates directly from the source.


But before you jump to the installation methods, removing the previous installation of Docker is necessary.

And to do so, you can use the following command:

sudo apt purge docker-ce docker-ce-cli docker-buildx-plugin docker-compose-plugin 

Once done, you can proceed to the shown installation methods.

Install Docker on Debian 12 using Docker repositories

The main reason why I recommend using this method is you get hassle-free upgrades as repositories can easily be updated!

So first, use the following command to install prerequisites for this method:

sudo apt update && sudo apt install ca-certificates curl gnupg

Now, let's create a directory to store the keyrings using the following:

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

Next, download the GPG key and store it in the /etc/apt/keyrings/etc/apt/keyrings directory using the given command:

curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Once done, use the chmod command to change the permissions of the docker.gpg file:

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

And finally, use the following command to set up the repository for Docker:

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

The extra \ at the end of each line in the above command is just a way to add new line so that you can easily see the entire command. That's it!

Now, you can update the repository index and install Docker using the following command:

sudo apt update && sudo apt-get install docker-ce docker-ce-cli docker-buildx-plugin docker-compose-plugin

To verify the Docker installation, you can install the hello-world image:

sudo docker run hello-world
install docker hello world image

The hello-world docker image is tiny and solely aimed to check if Docker is running fine.

Here's a replay of all the above commands.

Installing Docker on Debian

Use Docker without sudo

If you noticed, while running a hello-world image, I used sudo.

And this may not be convenient. So how about you configure it in such a way that you don't have to use sudo?

To do so, first, create a docker group using the groupadd command:

sudo groupadd docker

Now, add the user to the group (docker):

sudo usermod -aG docker $USER

Now log out from the terminal and log back in to take effect from the changes.


If you're installing Docker in VM, then, it may require a restart to take effect from the changes you've made.

Let's put it to the test by running the hello-world image:

docker run hello-world
run docker images without sudo

And as you can see, I was able to get the same results without using sudo.

Using Docker without sudo

Uninstall Docker

First, stop the docker service using the following:

sudo systemctl stop docker

Then use the apt purge command in the following manner to remove the Docker from your system:

sudo apt purge docker-ce docker-ce-cli docker-buildx-plugin docker-compose-plugin 

If you're planning to do the fresh install or you don't want to have any previous data, then you can use the rm command to remove Docker files:

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

That's it! Docker is removed successfully.

Uninstalling Docker from Debian

Next: Learn the essential Docker commands

If you're just starting with Docker, I highly recommend you learn the essential commands first.

21 Essential Docker Commands [Explained With Examples]
A compilation of 21 executable and informative Docker commands for your quick reference.

If nothing else, at least learn the basics Docker commands to manage the containers.

Docker Commands for Managing Container Lifecycle
Learn the container life cycle concept. Also learn the Docker commands to manage each stage of the lifecycle of the containers.

I hope you will find this guide helpful.

About the author
Sagar Sharma

Sagar Sharma

A software engineer who loves to write about his experience with Linux. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world


Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.