Learn how to clean up or remove unused Docker containers, images, Networks, Volumes and build cache.
What is docker prune? Pruning is a term used in docker to remove or clean up unused containers, images, networks, volumes and cache. These are also called dangling container, dangling images, dangling networks and dangling volumes. These Docker objects are labelled as dangling when it is not tagged and is not referenced by any container
The docker prune command allows you to remove unused docker objects or any docker object that is nor rferenced by any container.
Commands Used In THis Video
1) Remove unused containers
sudo docker ps -a
sudo docker container ls
sudo docker container ls –all
sudo docker container prune
2) Remove unused images
sudo docker image ls
sudo docker image prune -f
3) Remove unused volumes
sudo docker volume ls
sudo docker volume prune -f
4) Remove unused networks
sudo docker network ls
sudo docker network prune
5) Remove unused of everything… clean house
Depending on the flags you use, you can perform the following clean up task.
a) sudo docker system prune
The above command will will remove the following items.
– all stopped containers
– all networks not used by at least one container
– all dangling images
– all dangling build cache
b) sudo docker system prune –volumes
The above command will will remove the following items.
– all stopped containers
– all networks not used by at least one container
– all volumes not used by at least one container
– all dangling images
– all build cache
c) sudo docker system prune –volumes -all
The above command will will remove the following items.
– 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
- What Docker objects need clean up
- Clean up Docker containers
- Cleaning Docker images
- Cleaning dangling images
- Cleaning all Docker images
- Cleaning Docker volumes
- Clean up Docker networks
- Clean up your system
Reference