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

标签 java docker memory jvm limit

我有一台 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。 :(

最佳答案

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

关于java - Docker run -m 没有设置限制(JVM 为 xms 和 xmx 占用了整个主机的大小),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49919657/

相关文章:

java - Intellij 依赖问题 - java.lang.NoClassDefFoundError

java - 使用leve包从xsd文件生成java类

Javafx:用鼠标在ImageView上绘图

docker - 验证 Docker 中的环境变量

docker - Hyperledger Fabric错误-尝试联系2个对等方。最后一个错误是错误:在截止日期之前无法连接

docker - 在 Windows Server 2019 上运行 Linux Docker 容器

C++写入具有 protected 内存的进程

html - Adobe Air HTML 动态图库——如何通过删除图片释放内存

java - jsp中不打印参数

linux - 为什么LD_PRELOAD的值在栈上