Image size of 90MB
is only size on disk, it doesn't have much to do with occupied memory (RAM).
When you start a Docker container on Linux, e.g.:
$ docker run -itd --name test busybox /bin/sh
74a1cb1ecf7ad902c5ddb842d055b4c2e4a11b3b84efd1e600eb47aefb563cb3
Docker will create a directory in cgroups fs, typically mounted in /sys/fs/cgroup
under the long ID of the container.
/sys/fs/cgroup/memory/docker/74a1cb1ecf7ad902c5ddb842d055b4c2e4a11b3b84efd1e600eb47aefb563cb3/
In order to make the path shorter I'll write
/sys/fs/cgroup/memory/docker/$(docker inspect -f "{{.Id}}" test)
instead. The directory contains number of plain text files read/written by the kernel.
When you run Docker container without -m / --memory
flag, the container would be able to allocate all memory available on your system, which would be equal to:
$ numfmt --to=iec $(cat /sys/fs/cgroup/memory/docker/memory.max_usage_in_bytes)
When you specify a memory limit e.g. -m 1g
$ docker run -itd --name test -m 1g busybox /bin/sh
Docker will write the limit into file memory.limit_in_bytes
:
$ numfmt --to=iec $(cat /sys/fs/cgroup/memory/docker/$(docker inspect -f "{{.Id}}" test)/memory.limit_in_bytes)
1.0G
This tells the Linux kernel to enforce hard memory limit on the container. In case that the container is trying to allocate more memory than the limit, the kernel will invoke the infamous OOM killer.
The "MEM USAGE" is probably read from memory.usage_in_bytes
, which is approximation of actual memory usage.
$ numfmt --to=iec $(cat /sys/fs/cgroup/memory/docker/$(docker inspect -f "{{.Id}}" test)/memory.usage_in_bytes)
312K
According to cgroups documentation more precise value can be obtained from memory.stat
file.
If you want to know more exact memory usage, you should use RSS+CACHE(+SWAP)
value in memory.stat(see 5.2).
Where you'd have to sum those 3 lines. Normally memory.usage_in_bytes
is good enough estimate.