diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/container-images/dockerfiles.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/container-images/dockerfiles.adoc index 50caeef07ff2..a4fb1fba9572 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/container-images/dockerfiles.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/container-images/dockerfiles.adoc @@ -2,17 +2,17 @@ = Dockerfiles While it is possible to convert a Spring Boot uber jar into a docker image with just a few lines in the Dockerfile, we will use the xref:container-images/efficient-images.adoc#container-images.efficient-images.layering[layering feature] to create an optimized docker image. -When you create a jar containing the layers index file, the `spring-boot-jarmode-layertools` jar will be added as a dependency to your jar. +When you create a jar containing the layers index file, the `spring-boot-jarmode-tools` jar will be added as a dependency to your jar. With this jar on the classpath, you can launch your application in a special mode which allows the bootstrap code to run something entirely different from your application, for example, something that extracts the layers. -CAUTION: The `layertools` mode can not be used with a xref:deployment/installing.adoc[fully executable Spring Boot archive] that includes a launch script. +CAUTION: The `tools` mode can not be used with a xref:deployment/installing.adoc[fully executable Spring Boot archive] that includes a launch script. Disable launch script configuration when building a jar file that is intended to be used with `layertools`. -Here’s how you can launch your jar with a `layertools` jar mode: +Here’s how you can launch your jar with a `tools` jar mode: [source,shell] ---- -$ java -Djarmode=layertools -jar my-app.jar +$ java -Djarmode=tools -jar my-app.jar ---- This will provide the following output: @@ -20,12 +20,12 @@ This will provide the following output: [subs="verbatim"] ---- Usage: - java -Djarmode=layertools -jar my-app.jar + java -Djarmode=tools -jar my-app.jar Available commands: - list List layers from the jar that can be extracted - extract Extracts layers from the jar for image creation - help Help about any command + extract Extract the contents from the jar + list-layers List layers from the jar that can be extracted + help Help about any command ---- The `extract` command can be used to easily split the application into layers to be added to the dockerfile. @@ -33,19 +33,19 @@ Here is an example of a Dockerfile using `jarmode`. [source,dockerfile] ---- -FROM eclipse-temurin:17-jre as builder -WORKDIR application +FROM bellsoft/liberica-runtime-container:jre-17-cds-slim-glibc as builder +WORKDIR /builder ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} application.jar -RUN java -Djarmode=layertools -jar application.jar extract +RUN java -Djarmode=tools -jar application.jar extract --layers --destination extracted -FROM eclipse-temurin:17-jre -WORKDIR application -COPY --from=builder application/dependencies/ ./ -COPY --from=builder application/spring-boot-loader/ ./ -COPY --from=builder application/snapshot-dependencies/ ./ -COPY --from=builder application/application/ ./ -ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"] +FROM bellsoft/liberica-runtime-container:jre-17-cds-slim-glibc +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 ["java", "-jar", "application.jar"] ---- Assuming the above `Dockerfile` is in the current directory, your docker image can be built with `docker build .`, or optionally specifying the path to your application jar, as shown in the following example: @@ -61,4 +61,4 @@ Each of the `COPY` commands relates to the layers extracted by the jarmode. Of course, a Dockerfile can be written without using the jarmode. You can use some combination of `unzip` and `mv` to move things to the right layer but jarmode simplifies that. - +Additionally, the layout created by the jarmode is CDS friendly out of the box.