Stop copying around your dependencies over and over again!! Most of the time only the application classes change. Rebuilds should only push the changes!
Sample docker file for layered extraction of java libraries. What this does:
- extracts your fat spring-boot-generated JAR into separate layer directories
- from here, creates a docker image layer by layer
- typically only the application/ docker layer will have changed - the rest will load from docker cache
FROM openjdk:17.0.1-jdk-slim as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=tools -jar application.jar extract --layers --launcher
FROM openjdk:17.0.1-jdk-slim
WORKDIR application
COPY --from=builder /application/application/dependencies/ ./
COPY --from=builder /application/application/spring-boot-loader/ ./
COPY --from=builder /application/application/snapshot-dependencies/ ./
COPY --from=builder /application/application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]