Deploy standalone Spring MVC Application in Docker Container

In this post we will deploy simple standalone spring mvc application in Docker container. If you want to deploy the spring boot application in docker container, you can check my post Containerize Spring Boot application using Docker  .

We know that in spring boot application there is embed Tomcat application server and run our app on top of it but in case of standalone spring mvc application we don't have embed Tomcat server , hence we need to deploy the application in explicit tomcat standalone server.

Process to deploy the spring mvc in docker container :

1) First we need to get the Tomcat image.
2) Second to deploy the war in tomcat we need to save it in tomcat webapps direcory.

Create Docker file 


FROM : Using docker FROM command we are fetching the tomcat image from the Docker Hub.
COPY : In the second line we are copying the war file in tomcat webapp directory.

Note :  Any war saved in the tomcat webapps folder will be installed on tomcat start up.

You can use docker file commands like RUN, COPY, itsADD etc to update config folder, for eg RUN rm -rf /usr/local/tomcat/webapps/ROOT will remove/uninstall the existing ROOT application.


Create Docker Image

sudo docker build -t springmvc2 .



Once the above command is successfull we can check the image by using the command sudo docker images . It will list down all the images .

Run the Docker image

sudo docker run -p 8080:8080 springmvc2

Once you run the above command you will the logs on the terminal as below :











If you see tomcat startup logs on the terminal that means application has been successfully deployed in docker container. Since we have mapped the port number 8080 our application can be accessed on the url : http://localhost:8080

Other important concepts :

Some time we get different kind of issue during deployment on Docker container. In that case below command comes very handy. 

sudo docker run --interactive --tty springmvc2 /bin/bash

Using this command you can go inside the docker container of the image you have created and verify different things like whether your files have been saved in correct location etc. 


This covers the concept of deploying the spring mvc application in docker container. If you have any doubt or want to add anything , then please comment below. 

Comments

Popular posts from this blog

Refactor Code : Separate Query from Modifier

HTTP : Must known Protocol (Part 1)