View summary of all Docker containers memory usage

You can get pretty much all resource usage information with docker stats, but what you will lack there is the summary.

However, with some command line magic you can get the summary. You can put this in a .sh script, and make it executable with chmod +x

mem_amount_total_with_unit=$(docker system info \
| grep 'Total Memory: ' \
| tr -d 'Total Memory: ')

unit=$(echo ${mem_amount_total_with_unit} \
| sed 's/[0-9\.]*//g')

mem_amount_total=$(echo ${mem_amount_total_with_unit} \
| sed 's/[^0-9\.]*//g')

mem_percent_used=$(docker stats --no-stream --format '{{.MemPerc}}' \
| tr -d '%' \
| paste -s -d '+' - \
| bc)


mem_amount_used=$(echo "scale=2; ${mem_amount_total} * ${mem_percent_used} / 100" \
| bc)

echo "Memory Amount Total: ${mem_amount_total}${unit}"
echo "Memory Amount Used: ${mem_amount_used}${unit}"
echo "Memory Percent Used: ${mem_percent_used}%"

After running the script ./, you will get something like this:

Memory Amount Total: 7.639GiB
Memory Amount Used: 5.55GiB
Memory Percent Used: 72.75%

On some systems, bc is not present. You might need to install it with yum install bc or apt-get install bc or similar (depending on your system OS).

Did you know that I made an in-browser image converter, where you can convert your images without uploading them anywhere? Try it out and let me know what you think. It's free.

Leave a Comment

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