Docker 运行 -m 不设置限制(JVM 占用整个宿主机的 xms 和 xmx 大小)

Docker run -m doesnt set the limit (JVM takes up the entire host machine's size for xms and xmx)

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

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

在 docker 统计信息中,它显示容器的内存限制为 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/