Docker – How does docker stats output relate to top output

dockermemory usagetop

I've got a process running in a Docker container on Linux, with a 2GByte memory limit. (The container is started with docker run --memory=2g.)

Here is what top says about it after it's been running for a while.

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 9016 root      20   0 7342132 4.652g 4.224g S 100.0  7.4  18828:28 blah

Here's the output of docker stats:

CONTAINER           CPU %               MEM USAGE/LIMIT     MEM %               NET I/O
d7032e5928b6        100.02%             2.076 GB/2.147 GB   96.68%              345 MB/199.1 MB

Then, after restarting it, top:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 5653 root      20   0 2787800 1.328g 1.030g S 100.0  2.1   0:37.57 blah

docker stats:

CONTAINER           CPU %               MEM USAGE/LIMIT     MEM %               NET I/O
10cefdce241f        99.97%              320.4 MB/2.147 GB   14.92%              36.34 kB/22.48 kB

So that matches up (very roughly) with RESSHR, which makes some sense to me – but the equivalent calculation for the output from the long-running container doesn't match up in the same way.

What exactly is Docker counting here? Can I match it up somehow with the output from top, or some other tool?

Best Answer

docker stats include file cache memory as well. It will be freed upon request, but it is counted as used.

Related Topic