How to Remove All Docker Images Locally
Table of Contents
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.
BASHdocker 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:
BASHdocker container ls
From here, we can now use this list to remove all containers and their volumes:
BASHdocker 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:
BASHdocker image ls
From here, we can now use this list to remove all images:
BASHdocker 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.
BASHdocker 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!
- How to Install Node on Windows, macOS and Linux
- Getting Started with Solid
- Managing PHP Dependencies with Composer
- Getting Started with Electron
- How to deploy a PHP app using Docker
- How to deploy a Node app using Docker
- Learn how to use v-model with a custom Vue component
- Using Puppeteer and Jest for End-to-End Testing
- Getting Started with Handlebars.js
- Learn how to build a Slack Bot using Node.js
- Creating a Twitter bot with Node.js
- Using Push.js to Display Web Browser Notifications