Deploying Spring Boot War in Tomcat running in Docker

Steps to Dockerize Spring Boot Application

If you want to run SpringBoot application as JAR file with Docker, check my other post — Running Spring Boot JAR with Docker

First things First — Lets create a WAR file

As you know, Spring Boot based application by default creates executable JAR. We need to configure a bit to make Spring Boot create a WAR file as output.

  1. Change packing to war in pom.xml

2. Configure a custom name for your war file by setting finalName property in spring-boot-maven-plugin


Remember : In order for your application to run in standalone tomcat, your code needs little tweaks. Please refer it here

Time to Dockerize our Application

Lets start with creating a Dockerfile

FROM tomcat:latest
ADD target/sample.war /usr/local/tomcat/webapps/
CMD ["", "run"]

DockerFile demystified

FROM — Base image on top of which our custom image is to be build

ADD — Copy war file into webapps folder inside Docker

EXPOSE — Expose port 8080 outside Docker container

CMD — The command to be executed when the Docker image is run

Here is our docker-compose.yml file

Now lets run the following command

> docker-compose up —-build

Since we specified DOT (.) in build, docker-compose will search for Dockerfile in current directory & will build the image with name specified in image property (in this case its test-img)

Now your application is running in Tomcat inside Docker !!

Source code —

Next :

Step by Step instruction on how to build docker image and start the Docker container via Jenkins

Twitter @IamVickyAV