Git: 2.49.0
Spring Boot: 3.5.7
Maven: 3.9+
Java: 25
Docker Desktop: Tested on 4.45.0
git clone https://github.com/deepaksorthiya/spring-boot-docker.gitcd spring-boot-dockerBuild Project
./mvnw clean package -DskipTestsRemove directory application if exists
rm -f -R applicationCreate Self Exploded Jar file
java -Djarmode=tools -jar target/spring-boot-docker-0.0.1-SNAPSHOT.jar extract --destination applicationRun Self Exploded Jar file
java -jar .\application\spring-boot-docker-0.0.1-SNAPSHOT.jarStarted Application in 2.309 seconds (process running for 2.54)
./mvnw clean package -DskipTestsrm -f -R applicationjava -Djarmode=tools -jar target/spring-boot-docker-0.0.1-SNAPSHOT.jar extract --destination applicationcd applicationTraining Run
java -XX:ArchiveClassesAtExit=application.jsa "-Dspring.context.exit=onRefresh" -jar spring-boot-docker-0.0.1-SNAPSHOT.jarProduction Run
java -XX:SharedArchiveFile=application.jsa -jar spring-boot-docker-0.0.1-SNAPSHOT.jarStarted Application in 1.338 seconds (process running for 1.487)
Build Project With AOT mode
./mvnw -Pnative -DskipTests clean packagerm -f -R applicationjava -Djarmode=tools -jar target/spring-boot-docker-0.0.1-SNAPSHOT.jar extract --destination applicationcd applicationjava -XX:ArchiveClassesAtExit=application.jsa "-Dspring.context.exit=onRefresh" "-Dspring.aot.enabled=true" -jar spring-boot-docker-0.0.1-SNAPSHOT.jarjava -XX:SharedArchiveFile=application.jsa "-Dspring.aot.enabled=true" -jar spring-boot-docker-0.0.1-SNAPSHOT.jarStarted Application in 0.92 seconds (process running for 1.066)
./mvnw -Pnative -DskipTests clean packagejava -Djarmode=tools -jar target/spring-boot-docker-0.0.1-SNAPSHOT.jar extract --destination applicationcd applicationExecute the AOT cache training run
java -XX:AOTMode=record -XX:AOTConfiguration=app.aotconf "-Dspring.aot.enabled=true" "-Dspring.context.exit=onRefresh" -jar spring-boot-docker-0.0.1-SNAPSHOT.jarCreate the AOT cache
java -XX:AOTMode=create -XX:AOTConfiguration=app.aotconf -XX:AOTCache=app.aot "-Dspring.aot.enabled=true" -jar spring-boot-docker-0.0.1-SNAPSHOT.jarRemove aotconf as its unnecessary now
rm app.aotconfRun AOT cache enabled
java -XX:AOTCache=app.aot "-Dspring.aot.enabled=true" -jar spring-boot-docker-0.0.1-SNAPSHOT.jarStarted Application in 0.817 seconds (process running for 0.988)
TBD
./mvnw clean -Pnative -DskipTests native:compile./mvnw clean -Pnative spring-boot:build-image -DskipTestsEnable Spring AOT
and add
<BP_SPRING_AOT_ENABLED>true</BP_SPRING_AOT_ENABLED>
<BP_JVM_CDS_ENABLED>true</BP_JVM_CDS_ENABLED><executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions><configuration>
<buildArgs>
<buildArg>--pgo</buildArg>
<buildArg>--gc=G1</buildArg>
<buildArg>-march=native</buildArg>
</buildArgs>
</configuration><env>
<!-- For native build -->
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<!-- For cds-aot build -->
<BP_SPRING_AOT_ENABLED>true</BP_SPRING_AOT_ENABLED>
<BP_JVM_CDS_ENABLED>true</BP_JVM_CDS_ENABLED>
</env>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BP_JVM_VERSION>25</BP_JVM_VERSION>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>-march=native</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
./mvnw clean spring-boot:build-image -DskipTests- OR for low image size and multi-stage build (Run from workspace where Dockerfile is located)
docker build --progress=plain --no-cache -f <dockerfile> -t deepaksorthiya/spring-boot-docker .- OR Build Using Local Fat Jar In Path
target/spring-boot-docker-0.0.1-SNAPSHOT.jar
docker build --build-arg JAR_FILE=target/spring-boot-docker-0.0.1-SNAPSHOT.jar -f Dockerfile.jvm --no-cache --progress=plain -t deepaksorthiya/spring-boot-docker .- OR if above not work try below command
you should be in jar file path to work build args
cd target
docker build --build-arg JAR_FILE=spring-boot-docker-0.0.1-SNAPSHOT.jar -f ./../Dockerfile.jvm --no-cache --progress=plain -t deepaksorthiya/spring-boot-docker .- Run In Docker Container
docker run -p 8080:8080 --name spring-boot-docker -it deepaksorthiya/spring-boot-docker| Dockerfile Name | Description |
|---|---|
| Dockerfile | multi stage docker file with Spring AOT and JDK24+ AOT Cache |
| Dockerfile.jlink | single stage using JDK jlink feature to reduce size |
| Dockerfile.jvm | single stage using with Spring AOT and JDK24+ AOT Cache |
| Dockerfile.native | single stage using graalvm native image using oraclelinux 9 |
| Dockerfile.native-distro | single stage using graalvm native image distroless linux image |
| Dockerfile.native-micro | single stage using graalvm native image micro linux image |
| Dockerfile.native-multi | multi stage using graalvm native image micro linux image |
| Dockerfile.springlayeredjar | multi stage using spring layererd layout jar |
| Dockerfile.springlayoutjar | multi stage using spring layout jar |
Note: In Dockerfile.jlink check /optimized-jdk-25. This will be created under OS root path
while onlyoptimized-jdk-25 (without slash) created path
specified in WORKDIR, Which is in this case /workspace/app
http://localhost:8080/
http://localhost:8080/server-info
http://localhost:8080/rest-client
http://localhost:8080/rest-client-error
http://localhost:8080/rest-server-error
http://localhost:8080/rest-client-delay
For further reference, please consider the following sections: