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

Marcin Narloch

Marcin Narloch

Creative and out-of-the-box thinker with strong interests and knowledge in technology and innovation.
Reset Git Branch Commits Previous post GCP Kubernetes Engine Cheat Sheet
Docker Building Blocks Next post Docker Volumes

Leave a Reply

Your email address will not be published. Required fields are marked *