52

Is it possible - and if yes, how - to have a self-refreshing view of current Docker containers printed by "docker ps" alike top/htop utilities?

Open Food Broker
  • 1,095
  • 1
  • 8
  • 31

3 Answers3

88

Use watch:

watch docker ps

See man watch

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • 5
    I had to install watch with brew first: `brew install watch`. Thanks! – Richard May 17 '17 at 20:04
  • it complains when I try to pass arguments like --format – George Katsanos Aug 06 '18 at 10:24
  • 1
    Use quotes: https://superuser.com/questions/276701/using-the-watch-command-with-an-argument-that-contains-quotes – hek2mgl Aug 06 '18 at 10:28
  • unfortunately still fails: `watch "docker stats --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'" ` – George Katsanos Aug 06 '18 at 10:34
  • 2
    Your --format didn't work for me. probably a version issue. But check this for example: `watch 'docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"' ` – hek2mgl Aug 06 '18 at 10:51
  • When you have [two levels of nesting](https://unix.stackexchange.com/a/23349/), prefer to use single quotes around the outer command, e.g., `watch 'sudo docker ps --format "table {{.Names}}\t{{.Status}}"'`. – Yamaneko May 11 '21 at 20:49
  • use `watch -d -n 10 docker ps` to highlight changes (`-d`) and update only every 10 seconds (`-n 10`). – Datz Aug 04 '21 at 07:19
30

Few options:

  1. You can try command docker stats, which will give you some details about current running containers id, cpu%, memory etc. Something similar to top/htop which you asked for.

  2. Command docker top CONTAINER [ps OPTIONS] : It displays the running processes of a container.

  3. There are also some applications available which gives nice view of your docker ecosystem. Eg- Kitematic, Kevana

Avichal Badaya
  • 3,423
  • 1
  • 21
  • 23
  • 3
    Should be the correct answer to me since it does not require additional tool (like `watch`) – teemoo Jul 12 '19 at 06:56
5

As alternative to watch, there is an alias shown to loop docker stats (watch: might not be always available by default)

This creates a bash alias "ds"

alias ds='while true; do TEXT=$(docker stats --no-stream $(docker ps --format={{.Names}})); sleep 0.1; clear; echo "$TEXT"; done'

from: https://github.com/docker/docker/issues/20973

Open Food Broker
  • 1,095
  • 1
  • 8
  • 31