How to Remove All Docker Images Locally
I recently needed to delete all Docker images on my machine.
I knew I could remove individual images.
docker image rm IMAGE_ID
But I didn’t want to do this manually for each image.
1. Remove All Containers
First, we’ll want to remove all containers prior to removing the images.
We can first view all of our containers.
docker container ls
Then delete all containers as well as any associated volumes.
docker rm -vf $(docker ps -a -q)
2. Remove All Images
Next, we can view all of our images.
docker image ls
And finally, we can delete all of our images.
docker rmi -f $(docker images -a -q)
If we don’t mind deleting everything, we can ignore everything before this section, and use
docker system prune -a --volumes
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all volumes not used by at least one container
- all images without at least one container associated to them
- all build cache
More Docker Articles
- How to Execute a Shell Command Immediately Inside a Docker Container
- How to Fix "Port is already allocated" Error in Docker
- How to Develop with TypeScript in Docker with Hot Reloading
- How to Build TypeScript for Production in Docker
- How to Secure a Docker Container with Distroless Images
- How to Access Environment Variables in React Production Build
- How to Dockerize the MERN Stack for Development
- How to Dockerize a Node.js/Mongo App with Live Reload (nodemon)
- How to Update Docker Containers on File Change