4

1) I use next to start a container:

docker run --name test -idt python:3 python -m http.server

2) Then, I try to validate memory usage like next:

a)
root@shubuntu1:~# ps aux | grep "python -m http.server"
root     17416  3.0  0.2  27368 19876 pts/0    Ss+  17:11   0:00 python -m http.server

b)
root@shubuntu1:~# docker exec -it test ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.9  0.2  27368 19876 pts/0    Ss+  09:11   0:00 python -m http.

c)
root@shubuntu1:~# docker stats --no-stream test
CONTAINER ID   NAME  CPU %    MEM USAGE / LIMIT     MEM %    NET I/O      BLOCK I/O   PIDS
d72f2ece6816   test  0.01%    12.45MiB / 7.591GiB   0.16%    3.04kB / 0B  0B / 0B     1

You can see from both docker host & docker container, we could see python -m http.server consume 19876/1024=19.1289MB memory (RSS), but from docker stats, I find 12.45MB, why it show container memory consume even less than the PID1 process in container?

rss        RSS      resident set size, the non-swapped physical memory that a task has used (in kiloBytes). (alias rssize, rsz).

MEM USAGE / LIMIT the total memory the container is using, and the total amount of memory it is allowed to use

Community
  • 1
  • 1
atline
  • 28,355
  • 16
  • 77
  • 113
  • "The docker cli also subtracts shared memory from the value before it is displayed." https://github.com/moby/moby/issues/32253 – Adiii Oct 09 '19 at 09:40
  • and this https://success.docker.com/article/the-docker-stats-command-reports-incorrect-memory-utilization – LinPy Oct 09 '19 at 09:42
  • @Adiii Seems, in that post, it's `ps memory value < docker stats value` while here it's `ps memory value > docker stats value`. I also guess some calculation formula not same for this 2 value, but I still failed to know how exactly `19.1289` could corresponding to `12.45`? I'm learning that github issue, but a little lost, could you add more? – atline Oct 09 '19 at 09:55

0 Answers0