Does docker need a linux image as a dependency to run embedded-jetty spring boot war file

Viewed 223

I have an embedded-jetty based spring boot war file and I am able to run it in my windows OS with the below command and it works fine.

java -jar my_app.war

Am new to docker, I want to run my my_app.war in a docker container.

Now to create an image of my_app.war, do I first need to include a linux image dependency and then add openjdk8 image ?

or

I can directly create an image for my_app.war by using openjdk8 image dependency alone ?

4 Answers

You should look into building from one of the images [here][1].

FROM openjdk:8-alpine
ADD ./path/to/war/my_app.war dir-in-container/my_app.war
CMD ["java", "-jar", "dir-in-container/my_app.war"]

This is from the top of my head, you might have to fiddle with it a little bit. Usually go for light images like Alpine, and as a general pointer, don't ADD or COPY your files in the base path of the container.

You can use both ways. Basically openjdk8 will also have some image dependency. it will directly give you openjdk with dependency resolved in case of inux image you have to resolve those dependency.

reference: https://hub.docker.com/_/openjdk

Yes. you need to add openjdk image.

You can build image like this with open-jdk-8.

FROM openjdk:8-jdk-alpine

VOLUME /tmp

ADD /build/libs/app.jar app.jar

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

I use Tomcat image as basis for war deployments:

Here is Dockerfile you can try if your project runs with Java 11

FROM tomcat:9.0-jre11-slim

COPY target/libs/binsy.war /usr/local/tomcat/webapps/
ENV JAVA_OPTS="-server -Xmx3168m -Xms3168m"
Related