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?
3
Answers
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 copyingcontext.xml
You have a few options to choose from if you wish to add to or modify the
context.xml
file.context.xml
file already within the image as part of the image build. Add aRUN
command using a command line tool likesed
to add the required<Resources>
element to the file.context.xml
(e.g. usingsed
as per option 1) before invoking the usual tomcat startup script. Using this mechanism you could also get thecacheMaxSize
value to use from an environment variable and thus allow run-time control of the value.Rather than modifying the Tomcat context at build time an interesting option could be to expose some parameters for modification at runtime.
Exposing these parameter for the runtime would allow you not to have to rebuild and deploy an image every time you need to fine tune a setting.
Those settings can be then defined via the environment variables passed to the container image at startup.
Variable which will be accessible to the application running within the container, in your case Tomcat
Recent versions (since latest v7.0) of Tomcat can handle that quite.
See the properties replacement feature, described in the Tomcat documentation here
Two ways to enable this feature:
-Dorg.apache.tomcat.util.digester. PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource
system variable to the JVM.catalina.properties
file: