I am using docker to deploy a tomcat container running a third party war
file.
My Dockerfile
looks something like this
FROM tomcat:7-jre8
ADD my.war ${CATALINA_HOME}/webapps/my.war
When I run the container tomcat expands my war
at runtime and I can happily access my app at http://my.ip.addr:8080/mywar/
.
However my problem is that I want to edit a couple of the config files within the war
. I don't really want to unpack and repack the war
file as that seems messy and hard to maintain.
I was hoping to be able to tell tomcat to expand the war
as part of my RUN
steps and then use ADD
to put in my custom files but I can't seem to find a way of doing this. The war only gets expanded when the CMD
executes and then I can't edit the files after that.
Docker images can now be edited simply and reliably. This is an example of a Dockerfile for a Zabbix monitoring container. To change the image used by an existing container, we must first delete it, then edit the Docker file to make the necessary changes, and then recreate the container using the new file.
I am not sure exactly how you would achieve it with docker or anything else, as i dont see anyway to ask tomcat to just expand the war before it actually starts. But as per standard practices its not a good idea to explode a war and tweak the contents. It kills the entire purpose of making a war.
Rather you should make changes to the app to read configuration from << TOMCAT_HOME >>/conf.
If you achieve this the only thing you will need to tell Docker is to ADD your configuration file to the containers tomcat conf folder.
Or if it is a must for you to tamper with war file this is what you can do: Explode the war manually (or by script) on your build machine and instead of adding war directly to the docker image, map the folder. Something like this
ADD ./target/app-0.1.0.BUILD-SNAPSHOT /var/lib/jetty/webapps/ROOT.
And then manually add all your files to desired destinations.
ADD login.jsp /var/lib/jetty/webapps/ROOT/Webapps, so on and so forth.
How about unzipping your war manually, before starting tomcat?
ADD my.war /tmp/my.war
RUN unzip /tmp/my.war -d /usr/local/tomcat/webapps/mywar
# Edit config files
# Now you can start tomcat...
CMD ["catalina.sh", "run"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With