Docker是否需要Linux镜像作为嵌入式Jetty Spring Boot WAR文件运行的依赖?

huangapple go评论98阅读模式
英文:

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

问题

我有一个基于嵌入式Jetty的Spring Boot WAR文件,我能够在我的Windows操作系统上使用以下命令运行它,并且它能正常工作。

java -jar my_app.war

我是Docker的新手,我想在一个Docker容器中运行我的my_app.war。

现在要创建my_app.war的镜像,我是先需要添加一个Linux镜像依赖,然后再添加openjdk8镜像吗?

还是我可以仅通过使用openjdk8镜像依赖直接创建my_app.war的镜像?

英文:

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 ?

答案1

得分: 1

你应该考虑使用这里的其中一张镜像来构建 [这里][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"]

这是我脑子里想到的,你可能需要稍微调整一下。通常选择像Alpine这样的轻量级镜像,并且作为一般指南,不要将文件ADD或COPY到容器的基本路径中。

英文:

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.

答案2

得分: 1

你可以两种方式使用。
基本上,openjdk8 也会有一些镜像依赖。
它会直接为你提供带有已解决依赖的 openjdk,对于 Linux 镜像,你需要解决这些依赖。

参考链接:https://hub.docker.com/_/openjdk

英文:

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

答案3

得分: 0

是的,您需要添加openjdk镜像。

您可以使用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"]
英文:

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"]

答案4

得分: 0

我使用Tomcat镜像作为war部署的基础:

以下是Dockerfile,如果您的项目在Java 11上运行,您可以尝试使用:

FROM tomcat:9.0-jre11-slim

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

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"

huangapple
  • 本文由 发表于 2020年4月7日 17:06:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/61076428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定