Is there a way to display the docker stats sorted by memory usage of the containers?
I am using the following command to display the container with their names and I
Building off of the previous answers I created the following function and put in in my alias file.
Every second it captures the dockers stats and then generates 4 tables sorted descending by CPU %, MEM USAGE, NET I/O, and BLOCK I/O.
Also, this does maintain the table headers :-)
function dks() {
watch -n 1 'STATS=$(docker stats --no-stream --format "table {{.Name}}\t{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}"); echo "$STATS" | (read -r; printf "%s\n" "$REPLY"; sort -k3hr) | head; echo; echo "$STATS" | (read -r; printf "%s\n" "$REPLY"; sort -k4hr) | head; echo; echo "$STATS" | (read -r; printf "%s\n" "$REPLY"; sort -k7hr) | head; echo; echo "$STATS" | (read -r; printf "%s\n" "$REPLY"; sort -k10hr) | head;';
}