beginnerDockerfile Instructions & Multi-Stage Builds
Final image still contains Maven and the full JDK despite 'minimizing' it
A single-stage Dockerfile does FROM maven:3.9-eclipse-temurin-21, builds the jar, then RUN rm -rf ~/.m2 to 'clean up'. The image is still 700MB+. Explain why and the correct fix. Expected reasoning: deleting files in a later RUN only adds a deletion marker layer — the earlier layer containing Maven, the JDK, and the dependency cache is still part of the image's layer history and still counted in size. The correct fix is a multi-stage build: build in the maven image, then COPY --from=builder only the resulting jar into a clean eclipse-temurin:21-jre-alpine final stage.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full DevOps Mastery library.
Final image still contains Maven and the full JDK despite 'minimizing' it