Companion code for "Dockerizing Spring Boot 4: Layered Jars, Buildpacks, Distroless and Image Size Benchmarks". Fat jar on JDK and JRE, layered jar on Debian, Alpine and distroless, jlink, the JDK 25 AOT cache, Paketo buildpacks and Jib, each measured for size on disk and pushed, rebuild delta, startup, user and shell. Also PID 1 and signal handling, the jdeps module gap, AOT cache mismatches and buildpacks memory calculation. Transcripts in docs/output/, regenerated by scripts/run-all.sh. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01C3TETMrqVUWeFkNtz3Jbo3
27 lines
1.6 KiB
Docker
27 lines
1.6 KiB
Docker
# 6. A custom runtime: jdeps works out which JDK modules the application needs, jlink builds a
|
|
# JRE containing only those, and it goes onto distroless java-base (glibc, no JRE of its own).
|
|
# See docs/05-jlink.md for the module list this produced and the one it initially missed.
|
|
FROM eclipse-temurin:25-jdk AS builder
|
|
WORKDIR /builder
|
|
COPY target/app.jar application.jar
|
|
RUN java -Djarmode=tools -jar application.jar extract --layers --destination extracted
|
|
# jdeps cannot see modules loaded reflectively. jdk.management is the one this application
|
|
# needs: without it Micrometer silently drops 15 metrics, GC pauses and CPU usage among them.
|
|
ARG EXTRA_MODULES="jdk.management"
|
|
RUN MODULES="$(jdeps --ignore-missing-deps -q --recursive --multi-release 25 --print-module-deps \
|
|
--class-path 'extracted/dependencies/lib/*' extracted/application/application.jar)" \
|
|
&& MODULES="${MODULES}${EXTRA_MODULES:+,$EXTRA_MODULES}" \
|
|
&& echo "jlink modules: $MODULES" | tee /builder/modules.txt \
|
|
&& jlink --add-modules "$MODULES" --strip-debug --no-man-pages --no-header-files \
|
|
--compress=zip-6 --output /builder/jre
|
|
|
|
FROM gcr.io/distroless/java-base-debian13:nonroot
|
|
COPY --from=builder /builder/jre /opt/jre
|
|
COPY --from=builder /builder/modules.txt /opt/jre/modules.txt
|
|
WORKDIR /application
|
|
COPY --from=builder /builder/extracted/dependencies/ ./
|
|
COPY --from=builder /builder/extracted/spring-boot-loader/ ./
|
|
COPY --from=builder /builder/extracted/snapshot-dependencies/ ./
|
|
COPY --from=builder /builder/extracted/application/ ./
|
|
ENTRYPOINT ["/opt/jre/bin/java", "-jar", "application.jar"]
|