Ben Chuanlong Du's Blog

It is never too late to learn.

Check the Memory Limit of a Docker Container

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Docker 1.13+

Docker 1.13+ mounts the container's cgroup to /sys/fs/cgroup (this could change in future versions). You can check the limit using

cat /sys/fs/cgroup/memory/memory.limit_in_bytes

Older Version of Docker

  1. Install cgroup-tools.

    wajig update
    wajig install cgroup-tools
    
  2. Query the memory limit of the Docker container.

    cgget -n --values-only --variable memory.limit_in_bytes /
    

Notice that if a memory limit is not, both of the above methods will return a extremely large number. So to be safe, you'd take the minimum value before the above result and the memory of the host which can be get from the file /proc/memoinfo.

References

https://stackoverflow.com/questions/42187085/check-mem-limit-within-a-docker-container

Comments