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!
- Getting Started with TypeScript
- Getting Started with Svelte
- Getting Started with Express
- Create an RSS Reader in Node
- Getting Started with Electron
- Git Tutorial: Learn how to use Version Control
- How to deploy a Deno app using Docker
- How to deploy an Express app using Docker
- How to deploy a Node app using Docker
- Using Push.js to Display Web Browser Notifications
- Setting Up Stylus CSS Preprocessor
- Setting Up a Local Web Server using Node.js