How to Remove All Docker Images Locally

As you use Docker, you eventually accumulate images that you don't need anymore.
When that happens, you'll want to know how to delete all images to free up space.
In this post, we'll learn how to delete all Docker images on your machine.
Remove Single Docker Image
You can remove a single Docker image easily using the docker image rm
command.
Simply pass in the image id as the first argument.
docker image rm <image id>
If you don't know the image id, you can use the docker image ls
command to list all images.
Remove All Docker Containers
Before you can remove a Docker image, you need to remove all containers that are using it.
You get the list of all containers by using the ls
command:
docker container ls
From here, we can now use this list to remove all containers and their volumes:
docker rm -vf $(docker ps -a -q)
Remove All Docker Images
Now that we've removed all containers, we can remove all images.
Again, you can view all images by using the ls
command:
docker image ls
From here, we can now use this list to remove all images:
docker rmi -f $(docker images -a -q)
Pruning
Docker also has a prune
command that can be used to remove unused images and unused containers.
This command will remove all images and containers that are not used by any other container.
This is usually a safe command to run but definitely double-check to make sure you're not removing anything you need.
docker system prune
Conclusion
In this post, we've learned how we can remove Docker images one by one, and how to remove all Docker images from your local machine.
We also learned how we can use the prune
command to remove unused images and containers all at once.
Hopefully, this post has helped you free up some space on your machine. Thanks for reading!
If you want to learn about web development, founding a start-up, bootstrapping a SaaS, and more, follow me on X! You can also join the conversation over at our official Discord!
Leave us a message!