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 layersWORKDIR /appCOPY target/*.jar app.jarRUN java -Djarmode=layertools -jar app.jar extractFROM eclipse-temurin:21-jreWORKDIR /appCOPY --from=layers /app/dependencies/ ./COPY --from=layers /app/spring-boot-loader/ ./COPY --from=layers /app/snapshot-dependencies/ ./COPY --from=layers /app/application/ ./USER 65532ENTRYPOINT ["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.