docker-library/tomcat

Tomcat Docker Image not respecting webapp's context.xml?

HiranChaudhuri opened this issue · 4 comments

Hello there.

I am building a webapp that defines which context path it should be deployed on through an embedded context.xml.
When deploying that application on a locally installed Apache Tomcat 10.0.13 it works as expected.

However when integrating the same webapplication into tomcat:10.0-jre11-openjdk-slim the application always gets deployed under the war file name, not the name contained in context.xml. This is annoying since the war file name is myproject-version.war, and the context path I'd like to see the application under is myproject only.

What may be going wrong?

The image currently resolves to OpenJDK 11.0.13+8 and Apache Tomcat 10.0.14

I'm definitely not the best person to answer this (I'd really suggest trying a dedicated support forum, such as the Docker Community Forums, the Docker Community Slack, or Stack Overflow or even something more Tomcat-specific), but maybe https://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Naming is related?

(Especially the part about it ignoring the path defined in META-INF/context.xml if certain settings are enabled, which this image might be enabling by default?)

I strongly disagree some Tomcat-related forum will help. On Tomcat installed the 'normal' way the war deployment works as expected. The problem only occurs when using the container created in this project.

So if I were to ask about this container image in another forum I guess the issue is rejected straight away.

So I tried to investigate. It seems META-INF/context.xml is still supported in Tomcat 10:
https://tomcat.apache.org/tomcat-10.0-doc/config/context.html
This is in sync to my perception with a self-installed Apache Tomcat 10.0.13.

The content of the file in my war is

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myproject"/>

According to https://tomcat.apache.org/tomcat-10.0-doc/config/context.html the context path attribute...
must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase.

So from this statement it seems Tomcat 10.0.14 bundled in this container behaves more to the documentation than the self installed 10.0.13 one which also should have ignored the new context path. To be fair, this misleading context.xml file has been generated by my IDE so I took it's correctness for granted.

As a workaround I renamed my war file, and for maximum comfort I renamed it to ROOT.war at the stage where it gets added to the container.

Unfortunately, I don't think there's much more we can do to help here. 🙈