containers icon indicating copy to clipboard operation
containers copied to clipboard

[bitnami/tomcat:9.0.89] Can't set JAVA_OPTS in tomcat image, always overwritten by default.

Open Forgrim opened this issue 1 year ago • 0 comments

Name and Version

bitnami/tomcat:9.0.89

What architecture are you using?

amd64

What steps will reproduce the bug?

  1. Run the container with this command to get an interactive shell and set JAVA_OPTS enviroment: docker run -it -e JAVA_OPTS="-XX:MaxRAMPercentage=70 -XX:+UseZGC -XX:+ZGenerational" --name tomcat bitnami/tomcat:latest bash
  2. Print the JAVA_OPTS to ensure it is set correctly: echo $JAVA_OPTS
  3. Print tomcats setenv.sh, which is called by catalina.sh before it starts the tomcat server: cat /opt/bitnami/tomcat/bin/setenv.sh
  4. See in line 6, that JAVA_OPTS gets overwritten.

What is the expected behavior?

I expect that the JAVA_OPTS that I set on the container are also set on the tomcat process.

What do you see instead?

-Djava.awt.headless=true -XX:+UseG1GC -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true -Duser.home=/opt/bitnami/tomcat is always set, regardles what the JAVA_OPTS env holds.

Additional information

JAVA_OPTS is listed in the section for the customizable environment variables, but it currently is not customizable.

There is a setenv.sh template which sets JAVA_OPTS to the default value at the image buildtime.

  • Tomcats setenv.sh template: https://github.com/bitnami/containers/blob/main/bitnami/tomcat/9.0/debian-12/rootfs/opt/bitnami/scripts/tomcat/bitnami-templates/setenv.sh.tpl
  • Template gets rendered in: https://github.com/bitnami/containers/blob/main/bitnami/tomcat/9.0/debian-12/rootfs/opt/bitnami/scripts/tomcat/postunpack.sh#L44
    • This calls tomcat-env.sh at buildtime, which sets JAVA_OPTS to the default.
  • Which is run in the Dockerfile: https://github.com/bitnami/containers/blob/main/bitnami/tomcat/9.0/debian-12/Dockerfile#L53

We need to overwrite the JAVA_OPTS to change the garbage collector.

Forgrim avatar Jun 14 '24 10:06 Forgrim