How to Completely Uninstall Docker from Ubuntu
Completely uninstalling Docker from Ubuntu means removing its main software and all leftover files. Docker is a tool that lets you run applications in special, separate boxes called containers, which package everything an app needs.
To fully clean up Docker, you need to delete not just the main program but also any old containers, images, and stored data left behind. Simply removing the Docker package usually leaves these things on your system.
This thorough cleanup helps free up storage space on your Ubuntu machine. It’s also important if you’re trying to fix problems with Docker or want to start fresh with a new 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, it’s a good idea to clean up by deleting all your Docker images, containers, and volumes. This gets rid of old files you no longer need. Running `docker stop $(docker ps -a -q)` first stops any running containers so they can be safely removed.
Here’s how to do that.
First, stop the Docker containers that are running, then remove them.
Run the command below to do that.
docker stop $(docker ps -a -q)
This command will list all your Docker containers and then stop them. Once they are stopped, run the command below to remove them.
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
docker system prune -a
The command will perform the following actions:
- 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
A confirmation will appear; type ‘y’ and press Enter if needed.
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!