Java Spring Boot的Docker基本镜像(`FROM`)是什么? [英] What Docker base image (`FROM`) for Java Spring Boot?

查看:192
本文介绍了Java Spring Boot的Docker基本镜像(`FROM`)是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Java Spring Boot应用程序的Docker基本映像( FROM )?

What Docker base image (FROM) for Java Spring Boot application?

我只是从Docker开始,并且我看到 Dockerfile 中的 FROM 可以为Java定义映像,例如

I am just starting with docker, and I see that FROM inside Dockerfile can define image for Java like

FROM java:8

如果我是使用Gradle(或Maven)进行构建是更好的基础映像,可以避免在以后配置Gradle / Maven项目的共同点。

If I am building using Gradle (or Maven) is the better base image to start to avoid configuring later what is common for Gradle/Maven project?

当然,Spring Boot应用程序只是在build输出文件夹中的.jar文件中,关于如何使用Docker(对于使用标准构建工具构建的Java项目)运行的问题应该更少了

And of course Spring Boot application is just .jar file inside build output folder, there should be less questions about how to run with Docker (for Java project built with standard build tools)

推荐答案

关于如何将Spring-Boot与Docker集成的文档非常不错: https ://spring.io/guides/gs/spring-boot-docker/

There's a nice documentation on how to integrate Spring-Boot with Docker: https://spring.io/guides/gs/spring-boot-docker/

基本上,您可以在 src /中定义dockerfile main / docker / Dockerfile 并按以下方式配置docker-maven-plugin:

Basically you define your dockerfile in src/main/docker/Dockerfile and configure the docker-maven-plugin like this:

<build>
<plugins>
    <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.4.11</version>
        <configuration>
            <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
            <dockerDirectory>src/main/docker</dockerDirectory>
            <resources>
                <resource>
                    <targetPath>/</targetPath>
                    <directory>${project.build.directory}</directory>
                    <include>${project.build.finalName}.jar</include>
                </resource>
            </resources>
        </configuration>
    </plugin>
</plugins>

Dockerfile:

Dockerfile:

FROM frolvlad/alpine-oraclejre8:slim
VOLUME /tmp
ADD gs-spring-boot-docker-0.1.0.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

请注意,在此示例中, FROM frolvlad / alpine-oraclejre8:slim 是基于Alpine Linux的小型映像。

Note that in this example FROM frolvlad/alpine-oraclejre8:slim is a small-footprinted image which is based on Alpine Linux.

您还应该能够使用标准的Java 8映像(该映像基于Debian,并且占用空间可能会增加)。可以在这里找到可用的Java Baseimage的广泛列表: https:// github。 com / docker-library / docs / tree / master / openjdk

You should also be able to use the standard Java 8 image (which is based on Debian and might have an increased footprint) as well. An extensive list of available Java Baseimages can be found here: https://github.com/docker-library/docs/tree/master/openjdk.

这篇关于Java Spring Boot的Docker基本镜像(`FROM`)是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆