I build my image using below Dockerfile:
FROM java:jre-alpine
WORKDIR /target
ADD /target/test.jar test.jar
RUN sh -c 'touch /test.jar'
ENTRYPOINT ["java","/target/test.jar"]
And in my docker-compose.yml I have specified:
environment:
- CATALINA_OPTS=-Xmx256m -Xms128m
However when I use docker stats to check the memory usage, my docker container consumes much more memory than 256m.
BUT If I specify the JVM parameter in Dockerfile directly(see below), then docker stats shows the correct number:
FROM java:jre-alpine
WORKDIR /target
ADD /target/test.jar test.jar
RUN sh -c 'touch /test.jar'
ENTRYPOINT ["java","-Xmx512m","/target/test.jar"]
Could you give me some hints? I do not want to hardcode the -Xmx parameter in Dockerfile.
I ended up like this:
When I build the image, I specify in the Dockerfile:
ENTRYPOINT exec java $JAVA_OPTS -jar /target/test.jar
And then in the docker-compose.yml, I specify:
environment:
- JAVA_OPTS=-Xmx128m -Xms128m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With