Uninstall Docker from Ubuntu
Don't want to use Docker anymore. Learn how to properly and safely remove Docker from Ubuntu.
Previously, I explained how you can install Docker in Ubuntu with multiple methods but what if you no longer want to have Docker installed in your system?
Sure, you can use sudo apt remove docker
but it won't remove the configuration, containers, images, and volumes.
And this guide covers all!
How to uninstall Docker from Ubuntu
In this tutorial, I will walk you through the following sections:
- Removing Docker images, containers, configuration files, and volumes
- Uninstalling Docker packages
- Deleting Docker files from the system
So let's start with the first one.
Uninstall Docker images, containers, and volumes
Let's start by removing containers.
1. Removing Docker containers
First, stop the running containers using the following command:
docker stop $(docker ps -a -q)
Here, the $(docker ps -a -q)
part will list all the running and stopped containers and will pass them to the docker stop
command to stop all the running containers.
Once done, you can remove them using the following:
docker rm $(docker ps -a -q)
That's it!
2. Removing Docker images
To remove Docker images, all you have to do is execute the following command:
docker rmi $(docker images -a -q)
Like the previous command, the $(docker images -a -q)
, lists all the images including both active and intermediate images, and then passes them to the docker rmi
command to them.
3. Remove all Docker networks
If you wish to remove all the custom networks from Docker, then execute the following command:
docker network prune
4. Remove cache and volumes
The command that I am about to show you is very powerful and removes multiple unnecessary files at once including:
- Stopped containers
- Networks that are not used by at least one container
- Images that are not associated with at least one container
- Build cache
To do so, execute the following command:
docker system prune -a
Uninstall Docker packages
To remove every Docker package including compose plugin, buildx-plugin, and more, you have to execute one command and it will take care of all:
sudo apt remove docker-* --auto-remove
Here, the --auto-remove
flag will remove dependencies of Docker and is no longer required.
And that's all it takes to remove the Docker package from your system.
Remove leftover Docker files
Just removing the package is not enough. There are some files that are yet to be removed and have to be done manually.
All the Docker files are located inside the /var/lib/docker
directory. Use the following command to remove it:
sudo rm -rf /var/lib/docker
Next, remove the Docker group:
sudo groupdel docker
Now, remove the Docker socket using the given command:
sudo rm -rf /var/run/docker.sock
If you have Docker Compose installed, then, use the following command for the complete removal:
sudo rm -rf /usr/local/bin/docker-compose && sudo rm -rf /etc/docker && sudo rm -rf ~/.docker
That's it! Docker including all the files has been uninstalled from your system.
To verify the uninstallation, you can execute the docker
command and it should give you the following error:
docker
Looking for Docker alternatives? Here you go
If Docker wasn't good enough, there are multiple containerization solutions with different sets of features, and can be your next install.
To make things simple, we made a dedicated guide on Docker alternatives for your containerization needs:
I hope you will find this guide helpful.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.