我需要在docker容器上正确设置文件描述符限制我用ssh连接到容器(https://github.com/phusion/baseimage-docker)
已经尝试过:
输出总是一样的.
bash: ulimit: open files: cannot modify limit: Operation not permitted
Run Code Online (Sandbox Code Playgroud)
Gle*_*enn 42
最新的docker支持通过命令行和API设置ulimits.例如,docker run需要--ulimit <type>=<soft>:<hard>和你喜欢可以有许多的这些.所以,对于你的nofile,一个例子就是--ulimit nofile=262144:262144
dno*_*ode 27
经过一些搜索后,我在Google小组讨论中发现了这一点:
docker目前禁止这种增强安全性的能力.
这是因为主机系统的ulimit设置适用于docker容器.在容器中运行的程序可以更改主机的ulimit设置被视为安全风险.
好消息是您有两种不同的解决方案可供选择.
sys_resource从lxc_template.go并重新编译泊坞窗.然后你就可以将ulimit设置得尽可能高.要么
我应用了第二种方法:
sudo service docker stop;
改变了/etc/security/limits.conf中的限制
重启机器
运行我的容器
ulimit -a在容器中运行以确认已继承打开的文件限制.
请参阅:https://groups.google.com/forum/#!searchin/docker-user/limits/docker-user/T45Kc9vD804/v8J_N4gLbacJ
小智 8
我已经尝试了很多选项,并且不确定为什么上面建议的一些解决方案可以在一台机器上运行而不在其他机器上运行
一个有效且简单且可以按容器工作的解决方案是:
docker run --ulimit memlock=819200000:819200000 -h <docker_host_name> --name=current -v /home/user_home:/user_home -i -d -t docker_user_name/image_name
Run Code Online (Sandbox Code Playgroud)
如果使用 docker-compose 文件,基于 docker compose 版本 2.x 我们可以通过覆盖默认配置进行如下设置。
ulimits:
nproc: 65535
nofile:
soft: 26677
hard: 46677
Run Code Online (Sandbox Code Playgroud)
https://docs.docker.com/compose/compose-file/
实际上,我已经尝试了上面的答案,但是它似乎没有用。
为了使我的容器能够确认ulimit更改,我必须docker.conf在启动它们之前更新文件:
$ sudo service docker stop
$ sudo bash -c "echo \"limit nofile 262144 262144\" >> /etc/init/docker.conf"
$ sudo service docker start
Run Code Online (Sandbox Code Playgroud)
这就是我所做的。
ulimit -n 32000
在文件 /etc/init.d/docker 中设置
并重启docker服务
docker run -ti node:latest /bin/bash
运行此命令来验证
user@4d04d06d5022:/# ulimit -a
应该在结果中看到这个
open files (-n) 32000
[user@ip ec2-user]# docker run -ti node /bin/bash
user@4d04d06d5022:/# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 58729
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 32000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 58729
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
88129 次 |
| 最近记录: |