Having a custom catalina.sh when using a tomcat image from Docker

不问归期 提交于 2019-12-11 12:22:52

问题


I'm currently using Dockerfile to create Tomcat 6.0.44. It looks like this:

FROM tomcat:6.0.44-jre7

...

ADD catalina.sh /usr/local/tomcat/bin

Building the image from the Dockerfile is fine, but when I go to run it I get the following error:

exec: "catalina.sh": executable file not found in $PATH.

Any idea of how to fix this?

What I'm trying to do is pass in this parameter -DentityExpansionLimit=100000. Is there an easier way of doing it than in the catalina.sh?

Any help/suggestions would be greatly appreciated.

EDIT: I'm running a Redhat instance on EC2, and using Docker to extend a tomcat 6 image.


回答1:


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:

  1. 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.

  2. 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?




回答2:


This is mostly the case when you copy a shell script inside to the docker container but forget to set the executable bit on script.

On your host machine make sure you to execute chmod +x catalina.sh and then do the docker build.

Also I usually prefer override these files using volumes at run-time. But again that depends on your approach. The reason being tomorrow if a new version of image comes up then you don't need to rebuild your dockerfiles. But that is only if you could use the official images



来源:https://stackoverflow.com/questions/32603059/having-a-custom-catalina-sh-when-using-a-tomcat-image-from-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!