我已经创建了 85 个容器,所有容器都在我的 Linux 机器上运行相同的 .NET 核心应用程序镜像。 我对所有容器的 REST 调用是相同的,但每个容器使用的内存是不同的。
这是我不明白的。为什么内存使用不同,因为所有容器都运行相同的图像,并且 REST 调用也相同?
我可以使用以下方式获取容器使用的内存:
docker 统计
CONTAINER- 7827fe8127eb CPU - 0.00% MEM USAGE / LIMIT - 67.1MiB / 7.666GiB MEM % - 0.85% NET I/O - 76.4kB / 6.19kB BLOCK I/O - 42.7MB / 0B
从上面的统计数据我知道,我的容器使用的内存是 67.1 MB。
然后我进入容器内部,试图找出正在运行的进程和这些进程使用的内存。
docker exec -i -t 7827fe8127eb /bin/bash top
现在从“docker stats”获得的统计数据显示容器内存为 67 MB,那么
dotnet
进程使用的内存是多少?"RES"
列值是否提供进程内存?RES
大小为 92.70 MB,大于容器内存。我使用 Docker 引擎 API 来获取容器统计信息。但我不知 Prop 体是哪个属性指定了容器内存。
"memory_stats": { "usage": 72302592, "max_usage": 84365312, "stats": { "active_anon": 47865856, "active_file": 6664192, "cache": 24477696, "dirty": 4096, "hierarchical_memory_limit": 9223372036854772000, "inactive_anon": 8450048, "inactive_file": 9318400, "mapped_file": 16236544, "pgfault": 118960, "pgmajfault": 104, "pgpgin": 120339, "pgpgout": 105242, "rss": 47824896, "rss_huge": 8388608, "total_active_anon": 47865856, "total_active_file": 6664192, "total_cache": 24477696, "total_dirty": 4096, "total_inactive_anon": 8450048, "total_inactive_file": 9318400, "total_mapped_file": 16236544, "total_pgfault": 118960, "total_pgmajfault": 104, "total_pgpgin": 120339, "total_pgpgout": 105242, "total_rss": 47824896, "total_rss_huge": 8388608, "total_unevictable": 4096, "total_writeback": 0, "unevictable": 4096, "writeback": 0 }, "limit": 8231383040 },
因为我找不到,这里还有 67.1 MB。
首先,为什么每个容器使用的内存不同,因为它们运行相同的图像,执行的 REST 操作也相同?
一些容器被发现使用高达 93 MB,那么哪个容器进程实际上占用了最大内存?
最佳答案
关于linux - 如何获取在 Docker 容器中运行的进程的内存使用情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43588025/