gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:11:38 24 4
gpt4 key购买 nike

我有一台 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com