1

I'm trying to deploy .war,.aar,.xml and .properties file to tomcat docker container. I have used below Dockerfile with the base tomcat docker image.

FROM tomcat:7
RUN rm -rf /usr/local/tomcat/webapps/ROOT
COPY test-3.0.war /usr/local/tomcat/webapps/ROOT.war
COPY testone-3.0.aar /usr/local/tomcat/webapps/axis2/WEB-INF/services/
COPY ./conf/context.xml /usr/local/tomcat/conf/
COPY ./conf/server.xml /usr/local/tomcat/conf/
CMD ["catalina.sh", "run"]

Everything works as expected till now. It extracts the war file and starts the application inside the container.

But now i need to add/edit some of the property files inside "/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/" and "/usr/local/tomcat/webapps/ROOT/js" Like this.

COPY ./conf/applicationurl.properties /usr/local/tomcat/webapps/ROOT/WEBINF/classes/
COPY ./conf/memcache.properties /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/
COPY ./conf/um.properties /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/
COPY ./conf/pe.properties /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/
COPY ./conf/check.js /usr/local/tomcat/webapps/ROOT/js

What is the best approach to copy these files in to a running tomcat container ? I tried to build one more docker image with the above Dockerfile as a base image and copied aforementioned files in to a destination folder inside container but it deletes all the extracted war folder/files and it has only copied files inside /usr/local/tomcat/webapps directory.

I just need to add some of the property files and it shouldn't delete existing extracted folders inside webapps directory.

Can someone help me out with this?

4
  • A more programmatic approach would be to prep your java app so that you can point to where the config is located with a -D flag or something like that. You can then append your -D flag to the CATALINA_OPTS variable after copying your war-file Commented Jun 7, 2016 at 7:41
  • Another approach is to build your properties into a jar and deploy it to the tomcat/lib prior to starting your server. Commented Jun 7, 2016 at 7:42
  • Thanks for the suggestion. But i need to accomplish this by using aforementioned scenario in docker. Commented Jun 7, 2016 at 9:50
  • How did you end up solving this issue? I'm having the exact issue now. Deploying geoserver war, then need to access to WEB-INF etc, to add plugins such as mysql db plugin Commented Mar 15, 2017 at 1:05

2 Answers 2

2

Another option is to merely unzip the war file (you can just rename to zip, as its indeed a zip file).

So :

  1. Unzip war
  2. make all modifications needed to sub folders.
  3. Re-zip
  4. rename to .war
  5. deploy as per normal

I'm manipulating the war via DockerFile scripting. In my case, its deployment of Geoserver + adding plugin jars to /WEB-INF/lib

in short, unzip like this: unzip geoserver-2.10.2.war -d geoserver_war/

Hope that helps someone

Sign up to request clarification or add additional context in comments.

Comments

0

Can be solved by using a post script which can be called using nohup and then calling tomcat run.

postscript.sh has the post actions - Move the list of copy commands to a postscript.sh Before the copy commands, include some wait logic in the script to wait till tomcat has started. (It can be just sleep for some seconds or even grep the tomcat logs to search for server startup)

   #postscript.sh
   sleep 1000
   copy commands

Create a start script that calls the post script using nohup and then calls tomcat run

 #start.sh
 nohup postscript.sh & catalina.sh run

Then change the CMD to run the start.sh in the dockerfile. Also copy the postscript.sh and start.sh files to some location (/tmp for example) in the container.

  #....other contents
  COPY start.sh /tmp/start.sh
  COPY postscript.sh /tmp/postscript.sh
  CMD ["/tmp/start.sh"]

Hope this helps.

4 Comments

Thanks.But i'm getting following error when trying to run that image. "docker: Error response from daemon: Container command '/tmp/start.sh' could not be invoked". Do you have any idea on this ?
Check if start.sh is copied to /tmp folder. You can check the contents of /tmp by running a bash on the container.
While building the image it is copying to specific location. But when starting the container using docker run, container itself doesn't get started and throwing aforementioned error.Hence couldn't bash in to it.
You can run a bash on the docker image and then check the contents and see if the file is copied correctly. Try "docker run -it dockerimagename bash"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.