在 docker 中运行 jdk 8 在 arch linux 上突然中断,“无法分配文件描述符表 - 内存不足”

pas*_*oop 4 linux java arch-linux docker

昨天升级我的系统后,我试图重新启动我的 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) "$@"
Run Code Online (Sandbox Code Playgroud)

然后我发现我 dockerized 的任何 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.
#
Run Code Online (Sandbox Code Playgroud)

我刚刚发现了这篇文章,这似乎表明其他人在最近的 Arch 版本中遇到了类似的问题

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

pas*_*oop 6

使用以下命令更改容器上的 ulimit 时,运行 tomcat 有效

docker run -it --ulimit nofile=122880:122880 -m 3G --rm tomcat:8.0
Run Code Online (Sandbox Code Playgroud)

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

systemd/system.conf 
  55? #DefaultLimitNOFILE=1024:524288
Run Code Online (Sandbox Code Playgroud)

systemd 似乎更改了 DefaultLimitNOFile,这引发了我的问题。

本文介绍如何为docker设置ulimit。然而,这并没有为我削减它。我必须设置

ExecStart=/usr/bin/dockerd --default-ulimit nofile=65536:65536 -H fd://
Run Code Online (Sandbox Code Playgroud)

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