检查 docker 容器内的 mem_limit [英] Check mem_limit within a docker container
本文介绍了检查 docker 容器内的 mem_limit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用 mem_limit 过低的 docker 容器崩溃后,我如何在一个容器中检查这个容器的 mem_limit?如果 mem_limit 设置为低,我想在启动时打印错误消息并退出.
After some crashes with a docker container with a too low mem_limit, how can i check in a container the mem_limit of this container? I want to print an error message on startup and exit if the mem_limit is set to low.
推荐答案
在容器中为我工作,感谢 Sebastian 的想法
Worked for me in the container, thanks for the ideas Sebastian
#!/bin/sh
function memory_limit
{
awk -F: '/^[0-9]+:memory:/ {
filepath="/sys/fs/cgroup/memory"$3"/memory.limit_in_bytes";
getline line < filepath;
print line
}' /proc/self/cgroup
}
if [[ $(memory_limit) < 419430400 ]]; then
echo "Memory limit was set too small. Minimum 400m."
exit 1
fi
这篇关于检查 docker 容器内的 mem_limit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文