Is there any way to display container names in docker stats?

A bit hacky, but works:

docker stats $(docker ps | tail -n +2 | awk '{print $NF}')

tail -n +2 is there to remove docker ps header line, and finally awk '{print $NF}' prints the last column (i.e. container name) for every input line


Or, using plain "docker ps" instead of "awk"... note "--format" is normally used with "docker inspect":

docker stats $(docker ps --format '{{.Names}}')

2017-02-12 See manat's answer below (https://stackoverflow.com/a/42060599/72717). Docker 1.13.0 "stats" can display the container name in "--format":

docker stats --format "table {{.Name}}\t{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"

Since docker 1.13.0 (#27797), there's a format option which support container name. So you can run it like this:

docker stats --format "table {{.Name}}\t{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"

See Docker Formatting for full details.


docker stats $(docker ps | awk '{if(NR>1) print $NF}')

Tags:

Docker