Up to this point we were working with some of the core Docker building blocks, such as Docker Images, Docker Containers and Docker Volumes.
These resources, once created, take up some of your Docker platform resources, be it CPU, RAM or Disk Space. Your Docker environment can very quickly spin out of control if you don’t keep an eye on these core resources that you provisioned in this environment.
Therefore, in this final chapter of the Docker Building Blocks series, we’ll learn how to maintain a healthy Docker environment.
In the Docker System chapter we’ve learnt a very useful command docker system df which we’ll be using a lot here in order to get a quick snap-shot of our Docker system.
docker system df
System Housekeeping
This is probably the easiest way to clean your Docker system with one simple command docker system prune.
More details: docker system prune
Prune Unused Resources
docker system prune
Prune with Flags
docker system prune [FLAGS]
Flags
-a | Remove unused images too |
–volumes | Prune volumes too |
-f | Do not prompt for confirmation |
Containers Housekeeping
List all Containers
docker ps -a
Remove all Containers & its Volumes
docker rm -fv $(docker ps -aq)
Images Housekeeping
List all Dangling Images
docker rmi -f $(docker images -qf dangling=true)
Remove all Dangling Images
docker images -f dangling=true
Remove all Unused Images
docker image prune -af
Remove all Images in the System
docker rmi -f $(docker images -qf dangling=true)
docker rmi -f $(docker images -q)
docker image prune -af
Volumes Housekeeping
List all Dangling Volumes
docker volume ls -f dangling=true
Remove all Dangling Volumes
docker volume rm -f $(docker volume ls -qf dangling=true)
Remove all Unused Volumes
docker volume prune -f
Remove all Volumes in the System
docker volume rm (docker volume ls -qf dangling=true)
docker volume rm $(docker volume ls)
docker volume prune -f
<< Docker Volumes | Docker Housekeeping