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

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.io docker-ce docker-ce-cli
sudo apt-get autoremove -y --purge docker-engine docker docker.io 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:
ifconfig docker0 down
To delete the existing docker0 ethernet bridge:
brctl delbr docker0
Congratulations! You have just completely removed Docker from your system!
If my note helped, please consider buying me a coffee๐.
Cheers,
Lok
12 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!
I’m glad that it helps ๐
Thank you for the straight forward Docker removing method !!
No problem! Glad that it helps!
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๐
What about the directory `/var/run/docker`? Should that be removed, too?
Yes. You can do that in step 3.
You may want to run these two commands as well at the end:
# ifconfig docker0 down
# brctl delbr docker0
Thanks for the info! I’ve added a bonus step to the blog post๐.
This was the clearest and cleanest page of instructions I have ever used.
Many thanks to Lok C and all the individules given credit herein.
Great job — Bernie
Iโm glad that it helps๐