Skip to main content

How to See a Docker Container's CPU and Memory Use with docker stats

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Is a container using too much memory, or keeping the processor busy? docker stats shows each running container's CPU, memory, network and disk use. This guide checks a small web-server container, with real output from Docker 29.9.3.

Syntax​

Syntax
docker stats --no-stream CONTAINER
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" CONTAINER
PartWhat it means
CONTAINERThe container's name or ID. Without it, every running container
--no-streamPrint one snapshot and stop, instead of a live view
--format "table ..."Only the columns you name, such as {{.Name}}, {{.CPUPerc}} and {{.MemUsage}}

The reference: "Display a live stream of container(s) resource usage statistics", and for --no-stream: "Disable streaming stats and only pull the first result". The same commands work in PowerShell.

Prerequisites​

  • Docker: Docker Desktop on Mac or Windows, running.
  • A running container, such as one started with docker run -d --name web nginx:alpine.

Step 1: Take a Snapshot​

Terminal
docker stats --no-stream web
Output
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
df06ddb56bd9 web 0.00% 10.25MiB / 7.651GiB 0.13% 1kB / 84B 664kB / 4.1kB 11

docker stats --no-stream web in a terminal: CPU 0.00%, memory 10.25MiB of 7.651GiB, 0.13%, network and disk I/O, and 11 processes.

  • CPU %: 0.00%, the idle web server isn't working.
  • MEM USAGE / LIMIT: 10.25 MiB used of the 7.651 GiB Docker may give it.
  • PIDS: the number of processes in the container, 11.

Step 2: Keep Only Some Columns​

Terminal
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" web
Output
NAME CPU % MEM USAGE / LIMIT
web 0.00% 10.23MiB / 7.651GiB

The formatted docker stats in a terminal: only the NAME, CPU % and MEM USAGE / LIMIT columns for web.

table keeps the column headers, and \t separates the columns. The command printed the same in PowerShell 7.

Common Mistakes​

MistakeWhat happensDo this instead
Leaving out --no-streamA live view that refreshes until you press Ctrl+CAdd --no-stream for one snapshot
Expecting a stopped container in the listThe reference, for -a: "Show all containers (default shows just running)"Start it first, or check it's running with docker ps

Troubleshooting​

SymptomLikely causeFix
The command never endsIt's the live viewPress Ctrl+C: the live view stopped at once

FAQ​

Why is the memory limit so large?​

Without a limit of its own, a container may use all the memory Docker has, 7.651 GiB on this computer. Start it with --memory to set a lower one: a container run with --memory 64m showed 9.574MiB / 64MiB.

Can I watch several containers?​

Yes: leave out the name and docker stats shows every running container.

Conclusion​

docker stats --no-stream web showed the container at 0.00% CPU and 10.25 MiB of memory, and --format "table ..." kept only the columns needed.

Additional Resources​