> ## Content Index
> Fetch the complete content index at: https://itsfoss.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Install Docker on Debian 12
- URL: https://itsfoss.com/debian-install-docker/
- Published: 2023-07-07T07:12:37.000Z
- Updated: 2024-10-03T14:14:04.000Z
- Description: Learn how to install Docker on Debian 12 properly. Also learn to run Docker without sudo and remove it when not needed.
- Author: Sagar Sharma
- Tags: Installation 📥, #hide

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 docker.io

```

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 containerd.io 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](https://itsfoss.com/make-directories/) 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` directory using the given command:

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

Once done, [use the chmod command to change the permissions](https://linuxhandbook.com/chmod-command/?ref=itsfoss.com) 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] https://download.docker.com/linux/debian \
  "$(. /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 containerd.io 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](https://itsfoss.com/content/images/2023/07/install-docker-hello-world-image.png)

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](https://itsfoss.com/content/images/2023/07/Installing-Docker-Debian.svg)

## 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](https://learnubuntu.com/add-group/?ref=itsfoss.com):

```
sudo groupadd docker
```

Now, [add the user to the group](https://learnubuntu.com/add-user-group/?ref=itsfoss.com) (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](https://itsfoss.com/content/images/2023/07/run-docker-without-sudo.png)

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

![Using Docker without sudo](https://itsfoss.com/content/images/2023/07/Using-Docker-without_sudo.svg)

## Uninstall Docker 

First, stop the docker service using the following:

```
sudo systemctl stop docker
```

Then use the [apt purge command](https://itsfoss.com/apt-remove-purge/) in the following manner to remove the Docker from your system:

```
sudo apt purge docker-ce docker-ce-cli containerd.io 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](https://itsfoss.com/delete-files-folders-linux/):

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

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

That's it! Docker is removed successfully.

![Uninstalling Docker from Debian](https://itsfoss.com/content/images/2023/07/Uninstalling-Docker-Debian.svg)

## 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.![](https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png)Linux HandbookAvimanyu Bandyopadhyay![](https://linuxhandbook.com/content/images/2021/05/Essential-Docker-Commands.png)](https://linuxhandbook.com/essential-docker-commands/?ref=itsfoss.com)

If nothing else, at least learn the basics [Docker commands to manage the containers](https://linuxhandbook.com/container-lifecycle-docker-commands/?ref=itsfoss.com).

[Docker Commands for Managing Container LifecycleLearn the container life cycle concept. Also learn the Docker commands to manage each stage of the lifecycle of the containers.![](https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png)Linux HandbookDebdut Chakraborty![](https://linuxhandbook.com/content/images/2021/05/docker-container-lifecycle-diagram-1.png)](https://linuxhandbook.com/container-lifecycle-docker-commands/?ref=itsfoss.com)

I hope you will find this guide helpful.