In the previous steps, you learned how to view Docker disk usage in a human-readable format. Sometimes, you might need to process this information programmatically. Docker allows you to format the output of commands using the --format
flag.
To get the output of docker system df
in JSON format, you can use the --format json
option. This is useful for scripting or integrating Docker disk usage information into other tools.
Let's run the command with the JSON format option:
docker system df --format json
The output will be a JSON array containing objects representing the disk usage of each component (Images, Containers, Local Volumes, Build Cache).
For example, the output might look like this (formatted for readability):
[
{
"Type": "Images",
"Total": 2,
"Active": 2,
"Size": 205800000,
"Reclaimable": 0
},
{
"Type": "Containers",
"Total": 0,
"Active": 0,
"Size": 0,
"Reclaimable": 0
},
{
"Type": "Local Volumes",
"Total": 0,
"Active": 0,
"Size": 0,
"Reclaimable": 0
},
{
"Type": "Build Cache",
"Total": 0,
"Active": 0,
"Size": 0,
"Reclaimable": 0
}
]
This JSON output can be easily parsed by programming languages or command-line tools like jq
for further processing.