Docker主机与容器中的Ulimits [英] Ulimits in Docker host vs container

查看:837
本文介绍了Docker主机与容器中的Ulimits的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到这个问题的直接答案,但这是:

I wasn't able to find straight answer, to this question, but here it is:

比方说,我有一台主机,该主机的最大打开文件数为1024:

Let's say that I have a host which has max open files 1024:

[root@host]# ulimit -a
open files                      (-n) 1024

和在该主机中运行的docker容器,其内容如下:

and a docker container running in that host with:

[root@container]# ulimit -a
open files                      (-n) 1048576

那么,如果我尝试打开1024个以上的文件,那么容器会出现问题吗?我认为在这种情况下,容器的实际限制将是1024个文件.你觉得呢?

So will I have a problem in container if I try to open more then 1024 files? I think real limit in this case for container will be 1024 files. What do you think?

推荐答案

虽然有点晚,但我只是想消除对ulimit差异的怀疑.

Although its a little bit late, I just want to clear the doubts about the difference in ulimit.

如果在运行容器时确实设置了该值,则容器内显示的ulimit值来自主机OS.问题是,为什么在主机上运行相同命令时会看到不同的值?

If you do net set the value when running the container, the ulimit value displayed within the container comes from the host OS. The question is then why are you seeing a different value when running the same command from the host?

这是因为在主机中运行命令时,它正在显示其软限制.另一方面,容器显示的值是主机OS的硬限制.原因是您可以越过软限制.因此,从某种意义上说,硬限制实际上是真正的限制.您可以在此链接中找到有关ulimit的更多信息. a>.

This is because when running the command in the host, it is showing its soft limit. On the other hand, the value that the container is showing is the hard limit of the host OS. The reason for this is you are allowed to cross the soft limit. So in a sense, hard limit is actually the real limit. You can find more about ulimit in this link.

要查看硬限制,只需键入以下命令

To see the hard limit just type the following command

ulimit -Hn

您将看到值匹配.

不适用.您不能越过硬限制,但如果您是根用户,则可以增加硬限制.

N.B. You can not cross the hard limit but you can increase it if you are the root.

这篇关于Docker主机与容器中的Ulimits的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆