栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker nofile 配置说明

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docker nofile 配置说明

参考docker nofile 配置说明 - 简书

Linux通过nofile配置来限制进程能够打开的文件句柄。Linux默认nofile配置为1024,在高并发场景下已经无法满足需求。因此,通常需要将docker容器的nofile配置修改得大一些。

1. docker nofile介绍

Linux上通过ulimit命令查看nofile,该命令实质上是从/proc/self/limits读取相关信息,所以在/proc/self/limits中我们也可以找到Max open files信息:

root@allen-laptop:~# cat /proc/self/limits 
Limit                     Soft Limit           Hard Limit           Units     
... ...   
Max processes             22813                22813                processes 
Max open files            1024                 4096                 files     
... ...

由于Linux内核已经将nofile纳入cgroup控制,因此docker的nofile与宿主机的nofile是相互独立的。

例如,我在host机器上查看nofile:

root@allen-laptop:~# ulimit -n
1024

进入docker容器内,查看nofile:

root@allen-laptop:~# docker exec -it a44a6d87f9e9 /bin/bash
root@ubuntu-1:/# ulimit -n
524288

这意味着:我们修改宿主机上的nofile配置,实质上并不能影响docker容器内的nofile配置。

  1. docker nofile配置
    针对docker不同的启动方式,nofile配置也不一样。

2.1 在docker默认配置文件中修改nofile配置
如果docker采用service docker start启动,那么docker将默认从/etc/init/docker.conf配置文件中获取nofile配置 :

root@allen-10:/home/allen# cat /etc/init/docker.conf
description "Docker daemon"

start on (filesystem and net-device-up IFACE!=lo)
stop on runlevel [!2345]
limit nofile 524288 1048576
limit nproc 524288 1048576

可看出,docker容器默认nofile默认配置为524288(软限制)和1048576(硬限制)。 如果我们使用service docker start ,那么docker启动时将读取这个nofile配置,并应用到该宿主机上启动的所有容器。

2.2 在docker daemon命令参数中修改nofile配置
如果通过docker daemon命令启动docker ,那么需在命令中加入”–default-ulimit nofile”配置并重启docker即可。如:

docker daemon --default-ulimit nofile=524288:1048576 --default-ulimit nproc=524288:1048576 --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU} ${insecure_registries} --log-level=${DOCKER_LOG_LEVEL} --storage-driver=${STORAGE} >> $DOCKER_LOG_FILE 2>&1 &

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/828564.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号