Setting Java Heap Size for Spring boot project with embedded tomcat deployed as docker image

934 Views Asked by At

I have a spring boot REST application with embedded tomcat deployed in a docker container. My deployment YAML file has the following values set -

resources:
  limits:
    memory: 2.5G
  requests:
    memory: 512M

 env:
 - name: "SPRING_PROFILES_ACTIVE"
   value: "dev"
 - name: "JAVA_OPTS"
   value: "-Xms512m -Xmx1024m"

and the docerfile is -

FROM openjdk:8-jdk
ARG ARTIFACT_NAME
WORKDIR /app
COPY $ARTIFACT_NAME /app/app.jar
ENTRYPOINT exec java $JAVA_OPTS -jar /app/app.jar

But the JVM heapsize is not getting set to 1G. I have even tried using

-XX:+UnlockExperimentalVMOptions 
-XX:+UseCGroupMemoryLimitForHeap 
-XX:MaxRamFraction=2

but the result always shows MaxRamFraction as 4.

0

There are 0 best solutions below