Listing resource consumption

Over time, a Docker host can accumulate quite a bit of resources such as images, containers, and volumes in memory and on disk. As in every good household, we should keep our environment clean and free unused resources to reclaim space. Otherwise, there will come the moment when Docker does not allow us to add any more new resources, meaning actions such as pulling an image can fail due to lack of available space on disk or in memory.

The Docker CLI provides a handy little system command that lists how much resources currently are used on our system and how much of this space can possibly be reclaimed. The command is:

$ docker system df 

If you execute this command on your system, you should see an output similar to this:

TYPE          TOTAL   ACTIVE   SIZE      RECLAIMABLE
Images 21 9 1.103GB 845.3MB (76%)
Containers 14 11 9.144kB 4.4kB (48%)
Local Volumes 14 14 340.3MB 0B (0%)
Build Cache 0B 0B

The last line in the output, the Build Cache, is only displayed on newer versions of Docker. This information has been added recently. The preceding output is explained as follows:

If I want even more detailed information about the resource consumption on my system, I can run the same command in verbose mode using the -v flag:

$ docker system df -v 

This will give me a detailed list of all images, containers, and volumes with their respective size. A possible output could look like this:

Verbose output of the system resources consumed by Docker

This verbose output should give us enough detailed information to make an informed decision as to whether or not we need to start cleaning up our system, and which parts we might need to clean up.