【问题标题】:Docker run -m doesnt set the limit (JVM takes up the entire host machine's size for xms and xmx)docker run -m 不设置限制(JVM占用整个宿主机的xms和xmx大小)
【发布时间】:2018-04-19 11:11:38
【问题描述】:

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

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

在 docker stats 上,它显示容器的内存限制为 500MB。但是当我尝试这样做时

docker exec -it <containerID> /bin/sh

然后做一个“top”,它显示可用内存为 16GB..

不应该设置为 500MB 吗?

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

【问题讨论】:

标签: java docker memory jvm limit


【解决方案1】:

我认为这篇文章将帮助你理解为什么 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/

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
  • 这个摘录能回答你的问题吗?
  • @fly2matrix .. 是的.. 你的回答和 JDK 10 已经解决了这个问题.. 谢谢。干杯:)
猜你喜欢
  • 2011-09-03
  • 2015-07-07
  • 1970-01-01
  • 2012-08-01
  • 2010-11-18
  • 2020-06-29
  • 1970-01-01
  • 2013-01-16
  • 2021-10-05
相关资源
最近更新 更多