Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 78

    Dockerizing Spring Boot Apps

    Three good ways to containerise Spring Boot, in order of preference: buildpacks, Jib, hand-written Dockerfile.

    Course progress0%
    Focus
    3 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Three good ways to containerise Spring Boot, in order of preference: buildpacks, Jib, hand-written Dockerfile.

    Syntax reference

    2. Layered Dockerfile (full control):

    bash
    FROM eclipse-temurin:21-jre AS layers
    WORKDIR /app
    COPY target/*.jar app.jar
    RUN java -Djarmode=layertools -jar app.jar extract
    FROM eclipse-temurin:21-jre
    WORKDIR /app
    COPY --from=layers /app/dependencies/ ./
    COPY --from=layers /app/spring-boot-loader/ ./
    COPY --from=layers /app/snapshot-dependencies/ ./
    COPY --from=layers /app/application/ ./
    USER 65532
    ENTRYPOINT ["java","org.springframework.boot.loader.launch.JarLauncher"]

    Informative example

    1. Buildpacks (recommended):

    bash
    ./mvnw spring-boot:build-image \
    -Dspring-boot.build-image.imageName=acme/orders:1.0.0 \
    -Dspring-boot.build-image.builder=paketobuildpacks/builder-jammy-base
    Ready to mark this lesson complete?Track your journey across the entire course.