Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JAVA_OPTS ineffective to set the -Xmx in a Java Docker image?

my understanding is that the maximum amount of Java memory in a Docker container depends on the Docker constraints and the JVM settings. However, the only change I can see in the Max Heap Size depends on the docker –memory parameter.
For example, here I’m starting a Java program (openjdk17) that prints the Max memory settings:

docker run -it -e JAVA_OPTS="-Xmx1g" --memory 2g javatest
Max Heap Size = maxMemory() = 536870912

Same, changing the JAVA_OPTS:

docker run -it -e JAVA_OPTS="-Xmx64mb" --memory 2g javatest
Max Heap Size = maxMemory() = 536870912

The Dockerfile:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

FROM openjdk:17
COPY ./Example.class /tmp
WORKDIR /tmp
ENTRYPOINT ["java","Example"]

Is there any other env var that I can use to set the Max memory ?

>Solution :

I think the only way to make it work is to rewrite your ENTRYPOINT to include the JAVA_OPTS env variable. For example:

FROM openjdk:17
COPY ./Example.class /tmp
WORKDIR /tmp
ENTRYPOINT exec java $JAVA_OPTS Example
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading