Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JVM cant map reserved memory when running in Docker container

I cant seem to run java at all in a Docker container on my server. Even when issuing java -version, I get the following error.

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

According to this, java can't map 2.5Mb of space for reserved memory? This does not seem right...

I have the full log included at the end, but for the sake of some extra information, my system is reporting the following:

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

Can anyone point me in the right direction?

Full Log: https://gist.github.com/KayoticSully/e206c44681ce261674ba

Update

@Yobert nailed the problem and I highly suggest you read through the comments and chat log. Good info in there.

For those who want the final command that made Java work: setfattr -n user.pax.flags -v "mr" /usr/bin/java

If your distro does not have setfattr installed by default it should be included in the installable package attr through paceman, apt-get, etc.

like image 868
KayoticSully Avatar asked Dec 03 '14 02:12

KayoticSully


People also ask

How do I fix there is insufficient memory for the Java Runtime Environment to continue?

# There is insufficient memory for the Java Runtime Environment to continue. This is due to a known Java bug when process-limiting the virtual memory via ulimit (https://bugs.openjdk.java.net/browse/JDK-8071445). To resolve this, please set the max heap limits to a reasonable value.

Does Docker run on JVM?

The JVM runs inside the process, and interprets (or compiles) the Java byte code in your classes. A docker container is more heavyweight. There's the docker daemon, the docker container, which is actually a virtualized Linux instance, and then your JVM running under that.

Does Docker work with Java?

You can use Docker to run a Java application in a container with a specific runtime environment. This tutorial describes how to create a Dockerfile for running a simple Java application in a container with OpenJDK 17. It also shows how to create a Docker image with your application to share it with others.


2 Answers

I had this same problem when using a Grsec enabled kernel. For java to play nice, I had to disable MPROTECT on the java binary. You can use the paxctl utility for this:

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

You'll need to do paxctl -c on the binary first if you've never used it on that binary before:

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

More information about paxctl can be found at: http://en.wikibooks.org/wiki/Grsecurity/Additional_Utilities

like image 152
Yobert Avatar answered Oct 22 '22 03:10

Yobert


I had the same problem when running Docker on Alpine Linux, after enabling PaX soft mode it worked:

sysctl -w kernel.pax.softmode=1

Soft mode will disable most PaX features by default, therefore it is not recommended to enable it. The proper way is to use paxctl, as already mentioned above.

Also have a look here: https://en.wikibooks.org/wiki/Grsecurity/Appendix/Grsecurity_and_PaX_Configuration_Options#Support_soft_mode

like image 43
Sven Mohr Avatar answered Oct 22 '22 04:10

Sven Mohr