Oops, I messed up everything, How do I reset my Docker?
We have all been there. Working on a new platform and trying out some random github that looks cool, and you installed too many things and make a whole mess. Sometimes you just need to nuke it all and start over.
This is my notes transcribed into a guide on how to reset docker and start fresh.
To completely remove all Docker containers, networks, volumes, and images, effectively resetting your Docker environment to a clean slate, you can use the following commands:
1. Stop and remove all containers:
First, stop all running containers:
docker stop $(docker ps -aq)
Then, remove all containers (stopped and running):
docker rm $(docker ps -aq)
2. Remove all Docker networks:
Docker usually doesn’t remove the default networks (bridge
, none
, host
). You can remove all user-defined networks with:
docker network rm $(docker network ls -q)
3. Remove all volumes:
Volumes store persistent data for containers, so removing them will delete that data. To remove all volumes:
docker volume rm $(docker volume ls -q)
4. Remove all images:
If you also want to remove all Docker images (including both dangling and unused images):
docker rmi $(docker images -q)
5. Prune everything (Optional):
For an even more aggressive cleanup, you can use the prune
commands. This will remove unused containers, networks, volumes, and images that are not associated with a running container.
Remove all stopped containers, unused networks, volumes, and dangling images:
docker system prune -a --volumes
This set of commands will effectively clean up everything in your Docker environment, allowing you to start fresh.