Spring Boot 分层构建 Docker 镜像

Spring Boot Docker About 997 words

查看分层文件夹

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

Views: 1,484 · Posted: 2022-10-10

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

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

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


Today On History
Browsing Refresh