在Docker容器中运行时,JVM不能映射保留的内存

我似乎无法在我的服务器上的Docker容器中运行Java。 即使发出java -version ,我也会得到以下错误。

 root@86088d679103:/# java -version OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000035ce1000000, 2555904, 1) failed; error='Operation not permitted' (errno=1) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 2555904 bytes for committing reserved memory. # An error report file with more information is saved as: # //hs_err_pid17.log 

据此,java不能映射2.5Mb的空间用于保留内存? 这似乎不正确…

我在最后列出了完整的日志,但是为了获得一些额外的信息,我的系统报告了以下内容:

 root@86088d679103:/# uname -m x86_64 root@86088d679103:/# free -mh total used free shared buffers cached Mem: 15G 9.7G 5.8G 912K 148M 8.9G -/+ buffers/cache: 639M 14G Swap: 15G 0B 15G 

任何人都可以指向正确的方向吗?

完整日志: https : //gist.github.com/KayoticSully/e206c44681ce261674ba

更新

@Yobert钉住了这个问题,我强烈build议你阅读评论和聊天logging。 那里有很好的信息。

对于那些想要Java最终命令的人来说: setfattr -n user.pax.flags -v "mr" /usr/bin/java

如果您的发行版默认没有安装setfattr ,则应通过paceman,apt-get等方式将其包含在可安装的软件包attr中。

使用启用了Grsec的内核时,我遇到了同样的问题。 为了让Java玩起来不错,我不得不在Java二进制文件上禁用MPROTECT。 您可以使用paxctl实用程序来执行此操作:

 paxctl -m /usr/lib/jvm/java-7-openjdk/jre/bin/java 

如果以前从未在二进制文件中使用过,则需要先对二进制文件执行paxctl -c

 paxctl -c /usr/lib/jvm/java-7-openjdk/jre/bin/java 

有关paxctl的更多信息,请访问: http : //en.wikibooks.org/wiki/Grsecurity/Additional_Utilities

在Alpine Linux上运行Docker时,遇到同样的问题,启用了PaX软模式后:

 sysctl -w kernel.pax.softmode=1 

软模式默认会禁用大多数PaXfunction,因此不build议启用它。 如上所述,正确的方法是使用paxctl。

另外看看这里: https : //en.wikibooks.org/wiki/Grsecurity/Appendix/Grsecurity_and_PaX_Configuration_Options#Support_soft_mode

这也发生在我身上,我们减less了虚拟机上的内存大小,几天后,发现这个错误和服务并没有出现。

解决scheme::我们减less了这个问题的应用程序或服务的堆大小,服务再次罚款。