spring-boot 官方推荐的 docker 镜像制作方式(利用缓存,高效构建,减少磁盘存储)
Dockerfile:
FROM eclipse-temurin:8-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:8-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/ ./ CMD ["java", "org.springframework.boot.loader.JarLauncher"]
适用于 spring-boot 2.7.x,官方文档(2.7.18):https://docs.spring.io/spring-boot/docs/2.7.18/reference/html/container-images.html#container-images.dockerfiles