library initialization failed - unable to allocate file descriptor table - out of memoryAborte
问题描述:
使用Docker run container 的时候, 容器在启动几秒后自动退出 , 或者不退出,但里面的服务无法启动成功。 此例的服务是用 java -jar 来启动一个服务。 使用 docker logs 来查看日志时,只有一句日志: library initialization failed - unable to allocate file descriptor table - out of memoryAborted (core dumped)
解决思路及过程:
1 既然是报内存分配过程中,由于内存不够而 Aborted。 那就增大点儿内存再试试, 结果并没有成功。 我在其它机器启动这个java服务只分配了2G内存就启动成功,此处增大到8G, 仍无法成功。 所以这并不是内存不足导致的。
2 上网搜索,得到答案是需要设置 ulimit 下 nofile 和 nproc 这两个参数。 搜索到的结果有两种, 一种是说主机系统默认值是1024, 这个太小需要调大值 65535 或 100000 或 1048576 。 另一种是说docker启动容器时,有时这个值太大,需要调低一些。 总的来说就是这个值大小不合适,需要调整。 调整步骤有两个:
调整主机的系统默认值:
我先用 ulimit -n 查看了一下, 系统默认值是1024 。 然后在 /etc/profile 中添加 ulimit -n 65535 。 然后使用 source /etc/profile 命令使配置生效。
调整Docker下的默认值, 这个网上的方法很多,此处就随便说两种
方法一: 在执行 docker run 命令时添加参数 --ulimit nofile=65535:65535 --ulimit nproc=65535:65535
例如:
docker run -itd -p 7010:7010 --name service-a 64b87045a6fa --ulimit nofile=65535:65535 --ulimit nproc=65535:65535
方法二:
在 /etc/systemd/system/ 目录下, 创建 docker.service.d 目录
进入该目录,创建一个文件,名为 docker.conf
在文件中加入以下配置:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --default-ulimit nofile=65535:65535 -H fd://
1
2
3
啥意思呢? 就是说在执行docker命令时,直接默认使用该参数, 不需要在docker run 命令中定义了。
执行 systemctl daemon-reload (重启Docker daemon)
执行 systemctl restart docker (重启Docker 服务)
两边都配置好后, 再次开始测试, 然鹅结果依旧不行。 因为帖子上有很多赞,说明这个方法确实解决了一些道友的问题, 但我的问题不是如此。
3 我觉得也许是我第二步的配置有问题,但自己没发现导致问题依然存在。 于是就进入container中, 瞅瞅 container 中的 ulimit -n 值会是多少。 此时报了另外一个错: bash: ulimit: open files: cannot get limit: Operation not permitted.
再次搜索, 发现在Docker run命令中加上 --privileged=true 即可以有权限在container中执行这些命令。
例如: docker run -itd --privileged=true -p 7010:7010 --name service-a 64b87045a6fa 。 然后进入容器再次执行 ulimit -n 命令, 成功的输出了 65535 . 说明之前的配置确实是生效了的。
然鹅,就在这时发现, 原本几秒后就挂了的container, 这次不挂了。 以前不挂的container里面, java服务也能启来了, 不在报上面的错了。 问题解决了。 问题出在了这个 --privileged=true 参数上
分析:
虽然问题解决了, 但不能保证是 --privileged=true 的作用,还是这个参数再加上 nofile 和 nproc 的配置一起产生的作用。 然后我在另外一台同样的机器上,不改nofile 和 nproc, 只使用–privileged=true,发现也可以生效, 所以是 --privileged=true 单独作用产生的结果。
Privileged:
By default, Docker containers are “unprivileged” and cannot, for example, run a Docker daemon inside a Docker container. This is because by default a container is not allowed to access any devices, but a “privileged” container is given access to all devices (see the documentation on cgroups devices).
When the operator executes docker run --privileged, Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host. Additional information about running with --privileged is available on the Docker Blog.
这两句是官方文档给的解释。 意思是默认情况下,docker container 是以unprivileged方式运行的, 如果以 privileged 方式运行,就可以在一个container中再run一个docker daemon。之所以这样, 是因为 privileged 模式下, container可以有权访问主机里的任何设备, 还允许在AppArmor或SELinux中去修改一些配置, 也就是几乎可以在container中干和主机一样的事儿。
说实话,读了这个解释,我依然没明白为啥加了privileged就可以解决这个问题。 猜测大概是没有这个权限, container无法读取到主机的某些配置信息,但具体是哪个信息,还不得而知, 继续挖掘中…
—THE END—
library initialization failed - unable to allocate file descriptor table - out of memoryAborte的更多相关文章
- tomcat启动异常(严重: Dispatcher initialization failed Unable to load configuration. - [unknown location] )
严重: Dispatcher initialization failed Unable to load configuration. - [unknown location] at com.opens ...
- STM8程序在IAR中报错 unable to allocate space for sections
Error[Lp011]: section placement failed: unable to allocate space for sections/blocks with a total es ...
- 出现epoll failed: Bad file descriptor的原因
今天遇到了这个问题,之前找了半天原来是IO事件的socket描述符在epoll_ctl()处理之前关闭了. if(epoll_ctl(epollFd, EPOLL_CTL_DEL, ev->fd ...
- java.net.SocketException: recvfrom failed: EBADF (Bad file descriptor)
1. 问题说明: 与服务器之间进行socket通信的时候,客户端关闭socket之后,会抛出一个IOException,异常信息如下: java.net.SocketException: recvfr ...
- OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown
前言: 今天按照以往在Docker安装MongoDB的方式安装,但是到最后使用mongo命令执行mongodb命令的时候一直执行不成功,最后还是按照官网的Issues解决了. 创建并运行一个Mongo ...
- 近期编程问题——epoll failed:bad file descriptor
出现问题:epoll_wait:Bad file descriptor 原因:IO时间的socket描述符在epoll_ctl处理前就关闭了. 解决方法:不要在epoll_ctl之前关闭socket描 ...
- mac 启动php-fpm报错 failed to open configuration file '/private/etc/php-fpm.conf': No such file or direc
直接运行,有报错找不到配置文件. $ php-fpm [11-Jan-2014 16:03:03] ERROR: failed to open configuration file '/private ...
- 【Android】Tips for Android developer: “Conversion to Dalvik format failed: Unable to execute dex: null”
Androiddeveloper, I have met a strange problem when I want use a third party jar, it remained me tha ...
- org.springframework.beans.factory.BeanCreationException,Invocation of init method failed,Context initialization failed
G:\javaanzhuang\apache-tomcat-\bin\catalina.bat run [-- ::,] Artifact ssm_qingmu02_web:war exploded: ...
- Initializing the FallBack certificate failed . TDSSNIClient initialization failed
安装SQL后服务不能启动,报错: 2014-03-24 14:33:10.06 spid13s Error: 17190, Severity: 16, State: 1.2014-03-24 ...
随机推荐
- 15 Transformer 框架概述
博客配套视频链接: https://space.bilibili.com/383551518?spm_id_from=333.1007.0.0 b 站直接看 配套 github 链接:https:// ...
- 03 什么是预训练(Transformer 前奏)
博客配套视频链接: https://space.bilibili.com/383551518?spm_id_from=333.1007.0.0 b 站直接看 配套 github 链接:https:// ...
- Exchange限制邮箱用户每天/每分钟的发送邮件数量和速率
Exchange限制邮箱用户每天/每分钟的发送邮件数量和速率 近期遇到部分Exchange客服反馈内部邮箱账号密码被盗,给内部其他同事和外部邮箱发送大量钓鱼和诈骗邮件:对公司造成很大负面影响和经济损失 ...
- KubeSphere + Argo CD,实现真正的 GitOps!
来自社区用户 willqy 的分享 Argo CD 简介 Argo CD 是用于 Kubernetes 的声明性 GitOps 持续交付工具,应用程序定义,配置和环境应为声明性的,并应受版本控制,应用 ...
- 云原生爱好者周刊:使用 AWS 开源的 FireCracker 来创建和管理 K8s 集群
开源项目推荐 KubeFire 这个项目比较有创意,它使用 AWS 开源的轻量级虚拟化项目 FireCracker 来创建和管理 Kubernetes 集群,摒弃了传统的 qcow2 和 vhd 等虚 ...
- onethink自带编辑器内容无法修改
楼主小白一个,之前有大神带着进入onethink框架 在一个编辑页里面放两个编辑框的时候,悲催了--- 一个用作文本编辑,一个用于多图上传 发现前面的文本编辑的内容无法实现,后来楼主想调试一下 之前提 ...
- C++新版本特性
C++新特性 1.C++11 中的新特性 C++11 引入了许多新特性,包括自动类型推导.lambda 表达式.右值引用等.下面介绍其中的一些重要特性. 1.1 自动类型推导(Type Inferen ...
- CodeQL学习笔记(1)-QL语法(逻辑连接词、量词、聚合词、谓词和类)
最近在学习CodeQL,对于CodeQL就不介绍了,目前网上一搜一大把.本系列是学习CodeQL的个人学习笔记,根据个人知识库笔记修改整理而来的,分享出来共同学习.个人觉得QL的语法比较反人类,至少与 ...
- JS函数:递归函数与迭代函数
1.递归函数 : 程序中调用自己的函数 程序调用自身的编程技巧称为 递归( recursion).递归作为一种算法在程序设计语言中广泛应用. 一个过程或函数在其定义或说明中有直接或间接调用自身的一种方 ...
- 【FAQ】HarmonyOS SDK 闭源开放能力 —Push Kit(4)
1.问题描述: 目前华为推送API使用的是v2或者v1版本,请问目前最新的鸿蒙next使用v3版本是否兼容v2或者v1,反过来将v2或者v1的api可以推送鸿蒙next的设备吗? 解决方案: v3接口 ...