How to Completely Uninstall Docker from Ubuntu
Removing Docker from Ubuntu requires deleting the main program along with all leftover containers, images, and stored data. Docker is a software tool that runs applications inside isolated boxes called containers so they do not mess up the rest of your system.
Standard package removal usually leaves hidden files and large data folders lingering on your hard drive. A full cleanup reclaims valuable disk space and clears out stubborn software problems before you try a fresh installation.
Completely uninstall Docker by first removing all containers, images, networks, and volumes using docker commands. Then, remove the Docker packages with sudo apt remove docker-* –auto-remove and clean up residual directories like /var/lib/docker.
Delete Docker images, containers, and volumes
Before uninstalling Docker, clear out unnecessary images, containers, and volumes. Running `docker stop $(docker ps -a -q)` halts active containers so removal proceeds without errors.
Here is how to tackle the cleanup.
Halt all active containers first by running this command:
Run the command below to do that.
docker stop $(docker ps -a -q)
This command lists all Docker containers and stops them. Once they halt, run the command below to remove them entirely.
docker rm $(docker ps -a -q)
Next, remove Docker images. Run the command below to do that. This command lists all active and intermediate images and removes them from your system.
docker rmi $(docker images -a -q)
Next, remove all Docker networks. This command will remove Docker custom networks from the system.
docker network prune
Next, clear out the remaining cache and volumes with this prune command:
docker system prune -a
This single command sweeps away stopped containers, unused networks, unassociated images, and the build cache.
- Remove all stopped containers
- Remove networks that are not used by at least one container
- Remove Images without at least one container associated with them
- Remove build cache
Press y and hit Enter when the confirmation prompt appears.
To fully uninstall Docker packages and delete leftover files, you can run the following commands. This process ensures no residual Docker data remains on your Ubuntu system after the removal.
sudo apt remove docker-* --auto-remove sudo rm -rf /var/lib/docker sudo groupdel docker sudo rm -rf /var/run/docker.sock sudo rm -rf /usr/local/bin/docker-compose && sudo rm -rf /etc/docker && sudo rm -rf ~/.docker
That should do it!
Conclusion:
- The guide provided comprehensive instructions on how to uninstall Docker from Ubuntu Linux, covering the deletion of images, containers, volumes, and packages and removing leftover files and configurations.
- Following these steps will effectively free up space on the system and ensure the complete removal of Docker and its associated components.
- Users are encouraged to share feedback or additional insights through the comments section for future reference and improvement.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!