Home > database >  Changing Tomcat config - context.xml through dockerfile
Changing Tomcat config - context.xml through dockerfile

Time:09-27

I have developed a web app (maven, tomcat) in Intellij and managed to create a container through 'Services' tab in Intellij which was straightforward thanks to easy deployment config. During the process, I encountered that the cache size was not enough so I manually changed the context.xml (added <Resources cacheMaxSize="51200" />) file of tomcat manually locally after which the app ran smoothly.

To summarize the container creation in Intellij under services tab (see the bottom for the image):

 - pulling an image: tomcat:9.0.65-jre8
 - container name
 - bind ports: 127.0.0.1:8080:8080
 - bind mounts: mount host path which contains the war WITH /usr/local/tomcat/webapps

Though not sure, I guess the war file I created took already into account the change I made in the context.xml file since my application server is the tomcat I downloaded and made the change on its context.xml.

However, I also need to create a container with a dockerfile:

My dockerfile is:

FROM maven:3.8.4-jdk-8 as maven_builder
COPY . /usr/src/maven_pdfparse
WORKDIR /usr/src/maven_pdfparse
RUN mvn clean install -f /usr/src/maven_pdfparse && mkdir /usr/src/wars/
RUN find /usr/src/maven_pdfparse/ -iname '*.war' -exec cp {} /usr/src/wars/ \;
ADD pom.xml .

FROM tomcat:9.0.65-jre8
COPY --from=maven_builder /usr/src/wars/* /usr/local/tomcat/webapps

When I ran this on docker, I again got the 'insufficient cache' issue.

So how can I make the same change on context.xml when creating a dockerfile?

Or is there a way to get the dockerfile automatically when I create the container through deployment configuration?

enter image description here

CodePudding user response:

Please check this answer

Tomcat 8 throwing - org.apache.catalina.webresources.Cache.getResource Unable to add the resource

Where you'll need to update context.xml and rebuild your image with copying context.xml

CodePudding user response:

You have a few options to choose from if you wish to add to or modify the context.xml file.

  1. You can modify the context.xml file already within the image as part of the image build. Add a RUN command using a command line tool like sed to add the required <Resources> element to the file.
  2. You could also have a pre-modified version of the file and just copy it into the image to overwrite the existing one.
  3. You could add a custom startup command that modifies the context.xml (e.g. using sed as per option 1) before invoking the usual tomcat startup script. Using this mechanism you could also get the cacheMaxSize value to use from an environment variable and thus allow run-time control of the value.
  • Related