docker容器启动报错:library initialization failed - unable to allocate file descriptor table - out of memory

出现 "library initialization failed - unable to allocate file descriptor table - out of memory" 这个错误通常是因为 Docker 容器在启动时分配的文件描述符(file descriptors)数量不足。这可能是因为系统或 Docker 守护进程的 ulimit 设置不当。

一、查看系统或 Docker 守护进程的 ulimit

  1. 查看系统的 ulimit 设置
  • 使用命令在终端中查看当前用户的 ulimit 设置:
复制代码
ulimit -a
  • 要查看所有用户的 ulimit 设置,可以查看 `/etc/security/limits.conf` 文件:
复制代码
vi /etc/security/limits.conf
  1. 查看 Docker 守护进程的 ulimit 设置
  • 首先,找到 Docker 守护进程的 PID(进程 ID)。使用命令:
复制代码
pidof dockerd
  • 然后,查看 `/proc/<pid>/limits` 文件,其中 `<pid>` 是 Docker 守护进程的 PID。例如:
复制代码
cat /proc/$(pidof dockerd)/limits

二、修改系统或 Docker 守护进程的 ulimit(以下方式二选一)

1.修改 Docker 容器的 ulimit 设置:在启动容器时(即修改Dockerfile),可以单独为容器设置 ulimit 参数。例如,使用命令为容器设置文件描述符的限制。

复制代码
docker run --ulimit nofile=20480:40960 

2.修改 Docker 守护进程的默认 ulimit 设置:可以在 Docker 守护进程的配置文件中添加或修改 ulimit 参数。例如,在 /etc/systemd/system/docker.service 或 /usr/lib/systemd/system/docker.service 文件中,在 ExecStart 行后面添加 --default-ulimit nofile=65536:65536 参数(注意不能换行 ),然后重启 Docker 服务。

三、重启 Docker 服务(选择修改文件方式需要)

复制代码
1.重新加载 systemd 的配置
sudo systemctl daemon-reload
2.重启
sudo systemctl restart docker
相关推荐
Patrick_Wilson4 天前
从「改个端口」到 502:Next.js on k8s 的容器端口、Service 映射与 env 覆盖
docker·kubernetes·next.js
Suroy5 天前
DockerView-Go:用 Go 写一个终端 Docker 监控工具,顺便做了个 Web 仪表盘
docker
云恒要逆袭5 天前
运行你的第一个Docker容器
后端·docker·容器
宋均浩6 天前
# Docker 镜像瘦身实战:从 1.2G 到 80MB 的五个优化步骤
ci/cd·docker
程序员老赵6 天前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程
WangMingHua1117 天前
LM Studio Docker 部署——本地大模型一键启动
docker
曲幽8 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
武子康10 天前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
Alsn8613 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
程序员老赵13 天前
服务器没有桌面?Docker 跑个 Chrome,浏览器就能远程用
docker·容器·devops