Docker bulk image and container removal¶
Docker bulk removal involves using command-line substitutions to quickly delete all containers and images on a system, or using pruning commands to clean up specific unused resources like volumes and networks^[400-devops__03-Containerization__readme.md].
Removing All Containers and Images¶
To remove all containers, the system retrieves a list of all container IDs using docker ps -a -q and force removes them via docker rm -f.^[400-devops__03-Containerization__readme.md] Similarly, all images can be deleted by fetching a list of image IDs with docker images -q and force removing them using docker rmi -f.^[400-devops__03-Containerization__readme.md]
The combined commands for this process are:
docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -q)
Removing Unused Resources¶
Docker also provides commands to prune specific types of unused resources that are not associated with active containers^[400-devops__03-Containerization__readme.md].
- Volumes: To remove all volumes that are not currently in use, run
docker volume prune.^[400-devops__03-Containerization__readme.md] - Networks: To remove all unused networks, run
docker network prune.^[400-devops__03-Containerization__readme.md]
Related Concepts¶
- [[Docker]]
Sources¶
^[400-devops__03-Containerization__readme.md]