How can I remove all Docker images and containers from my local system?

I’ve accumulated a lot of unused Docker images by stopping containers with ctrl-c instead of using docker-compose down. Now I want to completely clean up. Is there a command or set of commands to Docker remove all images and containers at once—similar to a force cleanup?

Oh, I’ve been there too! The quickest way I clean everything—containers, images, networks, and volumes, is with this command:

docker system prune -a --volumes

Just be cautious, though, it’s pretty destructive. It’ll wipe out all unused stuff, so make sure you don’t need anything you’re about to lose. If you prefer being a little more careful, you can list everything first with docker images and docker ps -a

I usually prefer a slightly more controlled approach when I need a fresh start. I run these two commands:

docker container prune -f  
docker image prune -a -f

The first one clears stopped containers, while the second removes all dangling and unused images. I tend to avoid using --volumes unless I’m absolutely sure I don’t need the data. It’s safer for dev environments where volumes might contain things like databases that you don’t want to accidentally delete.

When things get really messy, I go full throttle and combine everything:

docker rm -f $(docker ps -aq)  
docker rmi -f $(docker images -q)

This forcefully deletes all containers and images manually. It’s more aggressive than pruning, but it’s sometimes necessary, especially if something is stuck or prune isn’t catching everything. Just make sure to check with docker ps -a and docker images before you do a mass delete!