How To Completely Remove Docker From Your Debian Based Linux

This is a simple note to myself of how to remove Docker from Ubuntu or Raspberry Pi OS (previously called Raspbian). Credit goes to Mayur Bhandare on Stack Exchange. I also added some explanation to some of the commands so you will have a better understanding of what they’re doing.

1. Identify which Docker package have you installed
dpkg -l | grep -i docker
For example, I’ve installed docker-ce and docker-ce-cli

The dpkg command is a package management command in Debian. Just like apt-get in Ubuntu, a Linux distro based on Debian. Since Raspberry Pi OS is also a descendant of Debian, this will work just fine. The above command is basically saying, give me a list of packages that contains the word “docker” in them.

2. Remove the packages

For me, I’ve only installed docker-ce and docker-ce-cli. So I will run the following commands.

sudo apt-get purge -y docker-ce docker-ce-cli
sudo apt-get autoremove -y --purge docker-ce docker-ce-cli

If you have more docker packages installed, you can add those packages names to the end of the commands above. For example:

sudo apt-get purge -y docker-engine docker docker-ce docker-ce-cli
sudo apt-get autoremove -y --purge docker-engine docker docker-ce 

The “-y” flag here is to answer “yes” to the command prompt when it asks you whether to remove a package. You can choose to remove the “-y” flag. Then you’ll see prompts like the following and you have to manually answer yes or y for every package.

3. Remove all the Docker related files

After that, you might want to remove all the Docker images, containers, volumes, and configurations. This is how:

sudo rm -rf /var/lib/docker /etc/docker
sudo rm /etc/apparmor.d/docker
sudo groupdel docker
sudo rm -rf /var/run/docker.sock

The “-rf ” flag is a combination of the “-r” and “-f” flags. “-r” means recursive. So the rm command can remove all the children folders and files of the target folder recursively. “-f” means force. It will ignore non-existent files, and never prompt before removing them. Be careful when you use these two flags together.

The groupdel command is to delete an existing docker user group.

Bonus: Deactivate Network Interface and Ethernet Bridge

If you want to take one step further, you can deactivate the docker0 network interface and delete the docker0 ethernet bridge. Here’s how(Credit: Thanks to anony for mentioning that!😁):

To disable docker0 network interface:

sudo ifconfig docker0 down

To delete the existing docker0 ethernet bridge:

sudo ip link delete docker0

The brctl command is deprecated. Updated the above command. Credit to Nicolas Raoul and Søren (Edited on 2024-03-26)

Congratulations! You have just completely removed Docker from your system!

If my note helped, please consider buying me a coffee😁.


16 replies on “How To Completely Remove Docker From Your Debian Based Linux”

Great, thanks! Had a lot of trouble with it, kernel not matching with cgroup etc. and all the tipps online i could get were nonsens.
with your help my system is clean after my first errors with docker. Not mentioned: clean the sources.list!

When I entered /var/run to remove docker.sock I noticed there’s a docker directory as well ‘/var/run/docker’. Forgive this noob, but should that be removed too?

Yes, you can remove it with the following command:
sudo rm -rf /var/run/docker.sock

This command is the 4th line in the 3rd step. I hope it helps😊

About the section “Deactivate Network Interface and Ethernet Bridge”:

1. You must prefix each command with sudo
2. The commands use `docker0` but the explanation read like “dockero”, which can be confusing. Maybe change the font or put `docker0` in inline source form.
3. brctl has been deprecated and does not exist anymore on most distributions. I successfully used this command instead: ip link delete docker0


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.