How to Completely Uninstall Docker

In this article, you'll learn step-by-step on how to completely remove Docker from a Debian-based Linux system.

2 min read
How to Completely Uninstall Docker
Photo by Karolina Grabowska on Pexels.

Last week, I was looking to recreate my personal infrastructure on a new server, but somehow, I screwed something in the process and was left with a Docker container that I could not delete... 🙈

Something similar had already happened to me in the past, and the fix that I had found in that time was to completely remove and reinstall Docker. 🤯

As I was only at the beginning of my process and didn't want to lose any more time, I decided to choose again this solution. But, my previous notes were a little bit scrambled, so I decided to improve them and to share them with you. Just in case you need it! 😉

So, without further ado, here is the complete procedure with some explanations if you want to learn more! 😎

In this procedure, my Linux distribution is Debian. If you use another distribution, you may need to modify the commands as they could be not suitable for you distribution.

And to remove the need of sudo before each command, I suggest that you run these command as root (with sudo su -). 😉

Step 1 – Remove Docker images, containers, and volumes

To completely remove Docker from your system, you'll need to remove any images, containers, and volumes that were created. To do this, use the following commands:

# Remove unused data
docker system prune --all --volumes

# Remove all services
docker service rm $(docker service ls -q)

# Remove all containers
docker rm -f $(docker ps -aq)

# Remove all images
docker rmi -f $(docker images -aq)

# Remove all volumes
docker volume rm $(docker volume ls -q)
Remove all data created and managed by Docker.

Step 2 – Stop Docker service

Before removing Docker from your system, you should stop the Docker service by running the following command:

systemctl stop docker
Shut down Docker.

This will ensure that Docker is not running in the background while you're removing it. 😉

Step 3 – Uninstall Docker

It's now time to remove Docker from the operating system. Run the followings commands:

# Uninstalls the Docker Community Edition (docker-ce) package from your Debian system
apt-get purge docker-ce -y

# Removes any remaining Docker packages and their dependencies that were not automatically removed by the previous command
apt-get autoremove --purge docker-ce -y
Uninstall Docker without prompts.

This will remove any packages that were installed as dependencies of Docker but are no longer needed.

Step 5 – Remove Docker group (optional)

If you had previously added users to the Docker users group to allow them to run Docker commands without sudo, you may want to remove the Docker group as well. Use the following command:

groupdel docker
This command will also remove the docker group from all users.

Step 4 – Remove Docker directories

Next, you'll need to remove any directories associated with Docker, including its configuration files and its storage location. Use the following commands:

# Remove the Docker configuration files
rm -rf /etc/docker

# Remove the Docker Daemon's storage location
rm -rf /var/lib/docker
Remove all directories created and used by Docker.


And that's it! You've now completely removed Docker from your system, along with any associated files and directories. 😎

If you want to reinstall Docker, you may now run the same commands as you typed when you installed it before! 😉