4

I have created Docker container and Tomcat is running in this container. How can I deploy a webapp or war file in Tomcat that is running in docker container.

rtruszk
  • 3,902
  • 13
  • 36
  • 53
  • possible duplicate of [Docker add warfile to official Tomcat image](http://stackoverflow.com/questions/27818856/docker-add-warfile-to-official-tomcat-image) – Mark O'Connor Aug 19 '15 at 13:08

2 Answers2

4

First create a Dockerfile:

FROM library/tomcat
RUN rm -rf /usr/local/tomcat/webapps/*
ADD ./relative/path_to_war.war /usr/local/tomcat/webapps/ROOT.war

Then build Docker image

$ docker build -t user/image_name .

And finally run docker container.

$ docker run --name container_name -p 80:8080 -d user/image_name

After that your webapp should be responding on Docker host's ip on default http 80 port.

You might need to link a database container to your webapp, see more on Docker documentation

Lauri
  • 4,336
  • 3
  • 18
  • 18
3

You can implement an effective way of using Tomcat Docker.

docker run -d -p 80:8080 -v <mount-path>:/usr/local/tomcat/webapps/ tomcat:8.0 

And then copy the .war files to the mounted volume. This would eliminate the need for restarting the Tomcat Docker each time when there is a code change. A zero downtime implementation could be achieved.

If it's a one-time deployment then you may create a custom Docker and copy the war file into /usr/local/tomcat/webapps/ and start the Docker.

Neeraj
  • 1,769
  • 3
  • 24
  • 41