I don't know if you already found a solution, but here's my suggestion. If I understand you correctly, you'd want to set a Java VM option for your webapp. Also, you try to alter the catalina.sh script with your own version so that it contains an additional Java VM option when running your webapp.
I think you should not have to alter the image with your own catalina.sh
. The script catalina.sh looks at the environment variables. You could set the environment variable CATALINA_OPTS to contain this setting. (There is also an environment variable JAVA_OPTS but that should be used for when you also want to apply these java options to some other Tomcat-native processes such as the stop process and version according to tomcat documentation.)
A more recent version of Tomcat (9) catalina.sh
explicitly states:
Do not set the variables in this script. Instead put them into a script setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
So, you could choose one of two options:
Use the standard Docker image of Tomcat and add only your webapp not your custom catalina.sh. When running a container of this image, set the CATALINA_OPTS environment variable set to the value of -DentityExpansionLimit=100000
.
Make a setenv.sh
script that sets the CATALINA_OPTS variable. Also add this script in your build file to the image. Version 6 catalina.sh
looks for this script in the CATALINA_HOME and CATALINA_BASE folder and executes it if it exists. Something like this (I didn't test it).
#!/bin/sh
echo "Setting JVM option Entity Expansion limit for application"
export CATALINA_OPTS="-DentityExpansionLimit=100000"
Option 2 has the advantage that you could force the correct default JVM options into the image instead of relying on people running the image to set the environment variable correctly.
Does that make sense?