Docker忽略limits.conf(试图解决“打开文件太多"错误) [英] Docker Ignores limits.conf (trying to solve "too many open files" error)

查看:242
本文介绍了Docker忽略limits.conf(试图解决“打开文件太多"错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个Web服务器,该服务器正在处理数千个并发Web套接字连接.为此,在Debian linux上(我的基本映像是google/debian:wheezy,在GCE上运行),其中打开文件的默认数量设置为1000,我通常只是将ulimit设置为所需的数量(64,000) .

I'm running a web server that is handling many thousands of concurrent web socket connections. For this to be possible, on Debian linux (my base image is google/debian:wheezy, running on GCE), where the default number of open files is set to 1000, I usually just set the ulimit to the desired number (64,000).

这非常有效,除了当我对应用程序进行docker化并部署时-我发现docker忽略了限制定义.我已经尝试了以下方法(全部在主机上,而不在容器本身上):

This works out great, except that when I dockerized my application and deployed it - I found out that docker kind of ignores the limit definitions. I have tried the following (all on the host machine, not on the container itself):

MAX=64000
sudo bash -c "echo \"* soft nofile $MAX\" >> /etc/security/limits.conf"
sudo bash -c "echo \"* hard nofile $MAX\" >> /etc/security/limits.conf"
sudo bash -c "echo \"ulimit -c $MAX\" >>  /etc/profile"
ulimit -c $MAX

经过一些研究,我发现人们可以通过以下方法解决类似的问题:

After doing some research I found that people were able to solve a similar issue by doing this:

sudo bash -c "echo \"limit nofile 262144 262144\" >> /etc/init/docker.conf"

并重新启动/重新启动docker服务.

and rebooting / restarting the docker service.

但是,以上所有方法均失败:当我的应用在容器内运行时,出现打开文件过多"错误(在没有docker的情况下执行以下操作即可解决此问题).

However, all of the above fail: I am getting the "too many open files" error when my app runs inside the container (doing the following without docker solves the problem).

我试图在容器内运行ulimit -a以获得ulimit设置是否起作用的指示,但是这样做会引发关于ulimit不是PATH一部分的可执行文件的错误.

I have tried to run ulimit -a inside the container to get an indication if the ulimit setup worked, but doing so throws an error about ulimit not being an executable that's a part of the PATH.

有人遇到这个问题和/或可以提出一种使Docker重新认识极限的方法吗?

Anyone ran into this and/or can suggest a way to get docker to recognzie the limits?

推荐答案

我能够通过以下配置来解决此问题:

I was able to mitgiate this issue with the following configuration :

我在docker计算机和主机计算机上使用了ubuntu 14.04 linux.

I used ubuntu 14.04 linux for the docker machine and the host machine.

主机计算机上,您需要:

  • 更新/etc/security/limits.conf以包括:* - nofile 64000
  • 添加到您的/etc/sysctl.conf中:fs.file-max = 64000
  • 重新启动sysctl:sudo sysctl -p
  • update the /etc/security/limits.conf to include :* - nofile 64000
  • add to your /etc/sysctl.conf : fs.file-max = 64000
  • restart sysctl : sudo sysctl -p

这篇关于Docker忽略limits.conf(试图解决“打开文件太多"错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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