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.
You can use Run command to start the tomcat container and then immediately stop it. This will cause the war to be expanded and then you can go ahead and modify the config files.
Ex:
Note: The you need to do all the steps in one run command. As Docker build will take each command and run it on the image generated from the previous command and commit. And incase of services, depending on a service that has been started in the previous RUN command will not work.
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.
Just add a
RUN
instruction which launches the server in the background, gives it a few seconds then exits i.e.You will need to give it long enough to expand the war file.
How about unzipping your war manually, before starting tomcat?