Log Docker Stats to a File

Published: Oct 1, 2019
Updated: May 3, 2021

Recently I needed to log the output of docker stats for a few of my containers in order to compare. The following snippet will log container stats to a file (stats.txt), and to stdout, every 1 second. Tweak it to your liking.

while true; do docker stats --no-stream | tee --append stats.txt; sleep 1; done