Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker DevOps


Spring Boot 分层构建 Docker 镜像

Spring Boot Docker 大约 997 字

查看分层文件夹

PS D:\demo\target> java -Djarmode=layertools -jar .\demo-0.0.1-SNAPSHOT.jar list   
dependencies
spring-boot-loader   
snapshot-dependencies
application

解压分层文件夹

PS D:\demo\target> java -Djarmode=layertools -jar .\demo-0.0.1-SNAPSHOT.jar extract

分层构建

FROM eclipse-temurin:11-jre as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM eclipse-temurin:11-jre
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

优点

使用Docker缓存层加速构建。

自定义分层构建

https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#packaging.layers.configuration

参考

https://docs.spring.io/spring-boot/docs/current/reference/html/container-images.html

阅读 120 · 发布于 2022-10-10

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批