Reputation: 3347
I have a working app using Spring Framework + AngularJs front-end.
I do deploy it on amazon AWS before by simply packaging mvn package
into .war file.
Now I need to setup a linux env in docker locally to debug some additional functionality (Using windows as the main OS) and preferably to deploy this docker container in future.
I do seen some articles on dockerizing the Spring Boot app.
This is the example dockerfile from spring.io
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD gs-spring-boot-docker-0.1.0.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
My question is - how do I run my .war file on docker container?
Upvotes: 0
Views: 1100
Reputation: 2621
If you configure/package your Spring Boot app as an executable .jar instead of a .war (Spring Boot Initializr will do this for you if you select the .jar option), then running it in your container is a matter of adding an entrypoint to run java with -jar and your jar name, like
ENTRYPOINT ["java", "-jar", "/opt/yourapp-0.0.1-SNAPSHOT.jar"]
Upvotes: 0
Reputation: 97
If you're looking to run this application on your local Linux machine, then you can create this Dockerfile in the same directory where the WAR file exists.
FROM tomcat:8.0.21-jre8
RUN [“rm”, “-rf”, “/usr/local/tomcat/webapps/ROOT”]
COPY dbconnect.war /usr/local/tomcat/webapps/ROOT.war
CMD [“catalina.sh”, “run”]
You can then build the Docker image and provide your custom tag:
docker build -t <your-username>/tomcat-example:latest .
Finally you can run this container.
docker run -p 8080:8080 -d --name tomcat <your-username>/tomcat-example:latest
You can check out these detailed examples here if need to run this application with a database or a web server.
https://github.com/dchqinc/dchq-docker-java-example
https://dzone.com/refcardz/java-containerization
Upvotes: 1
Reputation: 2604
You don't deploy a .war
file in docker just like you deploy it into a tomcat server. You need to have a main(String args[])
entry point which is also specified in your jar's manifest file. Your app.jar
specified as ENTRYPOINT
will then run your main()
. Inside the main()
you can run an embedded web server which runs your application.
Upvotes: 1