在 docker 中运行 jdk 8 时,Arch Linux 突然出现“无法分配文件描述符表 - 内存不足”的错误

在 docker 中运行 jdk 8 时,Arch Linux 突然出现“无法分配文件描述符表 - 内存不足”的错误

昨天升级系统后,我尝试重新启动 Docker 容器。我正在运行一个sbt(Scala 构建工具)容器。不幸的是,它停止工作并出现以下错误

library initialization failed - unable to allocate file descriptor table - out of memory/usr/share/sbt/bin/sbt-launch-lib.bash: line 46:    76 Aborted                 (core dumped) "$@"

然后我发现我docker化的所有java应用程序都停止工作了。所以我试着运行一个简单的tomcat。结果如下(底部被截断了,因为它有几百行代码)[Too many errors, abort]

docker run -it --rm tomcat:8.0                                                                                                                                             
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /docker-java-home/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
library initialization failed - unable to allocate file descriptor table - out of memory#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fb6b7b3e532, pid=1, tid=140422755079936
#
# JRE version: OpenJDK Runtime Environment (7.0_181-b01) (build 1.7.0_181-b01)
# Java VM: OpenJDK 64-Bit Server VM (24.181-b01 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 2.6.14
# Distribution: Debian GNU/Linux 8.10 (jessie), package 7u181-2.6.14-1~deb8u1
# Problematic frame:
# C  [libc.so.6+0x36532]  abort+0x232
#
# Core dump written. Default location: /usr/local/tomcat/core or core.1
#
# An error report file with more information is saved as:
# /usr/local/tomcat/hs_err_pid1.log
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
#   http://icedtea.classpath.org/bugzilla
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

我刚刚发现了这个帖子,似乎表明其他人在最近的 arch 版本中也遇到了类似的问题

https://github.com/neo4j/docker-neo4j/issues/155#issuecomment-471728441

答案1

使用以下命令更改容器上的 ulimit 即可运行 tomcat

docker run -it --ulimit nofile=122880:122880 -m 3G --rm tomcat:8.0

我发现(因为我的/etc文件夹是用 git repo 管理的)

systemd/system.conf 
  55│ #DefaultLimitNOFILE=1024:524288

看来 systemd 改变了 DefaultLimitNOFile,这引发了我的问题。

本文描述了如何设置docker的ulimit。但这对我来说没用。我必须设置

ExecStart=/usr/bin/dockerd --default-ulimit nofile=65536:65536 -H fd://

/etc/systemd/system/docker.service注意--default-ulimit适用于每次调用的标志docker

答案2

使用命令登录Docker容器docker exec -it imagename bash,输入命令ulimit -n 65536

相关内容