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

后端 未结 4 535
滥情空心
滥情空心 2021-01-31 14:27

I want to display state of all running container, so I could achieve it like the following:

docker stats $(docker ps -q)

CON         


        
相关标签:
4条回答
  • 2021-01-31 15:14

    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

    0 讨论(0)
  • 2021-01-31 15:26

    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}}"
    
    0 讨论(0)
  • 2021-01-31 15:27

    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.

    0 讨论(0)
  • 2021-01-31 15:28
    docker stats $(docker ps | awk '{if(NR>1) print $NF}')
    
    0 讨论(0)
提交回复
热议问题