Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA_OPTS/CATALINA_OPTS parameters not working with docker-compose.yml

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.

like image 380
Yashu Avatar asked Sep 01 '16 13:09

Yashu


1 Answers

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

like image 82
Yashu Avatar answered Nov 14 '22 02:11

Yashu