Docker File to Deploy a WAR file on Tomcat

In this post, I am going to show how to deploy a war file on Tomcat Server.

Instead of using Default Tomcat image from DockerHub, I have tried to download the tomcat server bundle and used it.

For this exercise, I have taken the sample.war file from Tomcat web site. Please refer

Once you have downloaded the sample.war file, then it’s time to create the Dockerfile.

Create Dockerfile and copy the below content in it.

FROM java

RUN curl -O
RUN tar xzf apache-tomcat-7.0.55.tar.gz
ADD sample.war apache-tomcat-7.0.55/webapps/
CMD apache-tomcat-7.0.55/bin/ && tail -f apache-tomcat-7.0.55/logs/catalina.out

Then it’s time to build and run the docker container.

Build the container:

docker build -t tomcat .

Run the container:

docker run -p 8080:8080 tomcat

Then access the browser and check http://localhost:8080/hello. You will be able to see the welcome message.

Please refer Deploy war file on Tomcat to know on how to use Tomcat image directly.