Docker run -m没有设置限制(JVM占用整个主机的xms和xmx的大小)

时间:2018-04-19 11:11:39

标签: java docker memory jvm limit

我有一台16GB RAM的服务器。我试图通过运行

来设置容器的内存限制
docker run -it -m 500M <image-name>

在docker统计信息中,它显示容器的内存限制为500MB。但是当我尝试做的时候

docker exec -it <containerID> /bin/sh

并执行“top”,它显示可用内存为16GB ..

不应该设置为500MB吗?

我需要它为500 MB的主要原因是我在每个容器中运行java应用程序。默认情况下,JVM的Xms为16gb / 64,Xmx为4gb。 :(

1 个答案:

答案 0 :(得分:2)

我认为这篇文章将帮助您理解为什么free和top在容器内无法正常工作。

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/