0

I have a server with 16GB RAM. I am trying to set the memory limit to the container by running

docker run -it -m 500M <image-name>

On the docker stats, it shows the container has the memory limit of 500MB. But when i try to do

docker exec -it <containerID> /bin/sh

and do a "top", it shows the available memory as 16GB..

Should it not be set to 500MB ?

The main reason why i need it to be 500 MB is I have java application running in each container. And by default the JVM takes 16gb/64 as the Xms and 4gb as Xmx. :(

Shrikey
  • 858
  • 3
  • 11
  • 34
  • What's the output of `docker stats` for that container? – Robert Apr 19 '18 at 11:30
  • https://stackoverflow.com/questions/20096632/limit-memory-on-a-docker-container-doesnt-work?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – nephilim_boy Apr 19 '18 at 11:33
  • One of the key features of Java 10 is better co-operation with Docker. You might want to look at Java 10. https://www.opsian.com/blog/java-on-docker/ – Peter Lawrey Apr 20 '18 at 18:16
  • @PeterLawrey . Yeah.. I am using Java 10 with experimental features turned on. :) – Shrikey Apr 23 '18 at 16:56

1 Answers1

2

I think this article will help you to understand why free and top doesn't work correctly inside containers.

Most of the Linux tools providing system resource metrics were created before 
cgroups even existed (e.g.: free and top, both from procps). They usually read 
memory metrics from the proc filesystem: /proc/meminfo, /proc/vmstat, 
/proc/PID/smaps and others.

Unfortunately /proc/meminfo, /proc/vmstat and friends are not containerized. 
Meaning that they are not cgroup-aware. They will always display memory 
numbers from the host system (physical or virtual machine) as a whole, which 
is useless for modern Linux containers

This causes a lot of confusion for users of Linux containers. Why does free 
say there is 32GB free memory, when the container only allows 512MB to be 
used?

https://fabiokung.com/2014/03/13/memory-inside-linux-containers/

fly2matrix
  • 2,351
  • 12
  • 13
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/19485999) – Martin Serrano Apr 19 '18 at 12:11
  • 1
    Does this extract answer your question ? – fly2matrix Apr 19 '18 at 12:19
  • @fly2matrix .. Yeah.. Your answer and JDK 10 has solved the prob.. Thanks. Cheers :) – Shrikey Apr 23 '18 at 16:57