From c50a5b395b2e69c206500195136cfc0ca1320854 Mon Sep 17 00:00:00 2001 From: Sebastiaan Fernandez Date: Thu, 9 Jul 2020 22:55:12 +0200 Subject: [PATCH 1/2] Restructure "Building Container Images" section See gh-22296 --- .../src/docs/asciidoc/spring-boot-features.adoc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index 15571dc3c5..1c5c6d59d0 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -8176,9 +8176,12 @@ If you need the `Mockk` equivalent of the Mockito specific <>, or by <>. + [[building-docker-images]] -== Building Docker Images -Spring Boot applications can be containerized by packaging them into Docker images. +=== Building Docker images A typical Spring Boot fat jar can be converted into a Docker image by adding just a few lines to a Dockerfile that can be used to build the image. However, there are various downsides to copying and running the fat jar as is in the docker image. There’s always a certain amount of overhead when running a fat jar without unpacking it, and in a containerized environment this can be noticeable. @@ -8186,7 +8189,7 @@ The other issue is that putting your application's code and all its dependencies Since you probably recompile your code more often than you upgrade the version of Spring Boot you use, it’s often better to separate things a bit more. If you put jar files in the layer before your application classes, Docker often only needs to change the very bottom layer and can pick others up from its cache. -=== Layering Docker Images +==== Layering Docker Images To make it easier to create optimized Docker images that can be built with a dockerfile, Spring Boot supports adding a layer index file to the jar. It provides a list of layers and the parts of the jar that should be contained within them. The list of layers in the index is ordered based on the order in which the layers should be added to the Docker/OCI image. @@ -8223,7 +8226,7 @@ For Gradle, refer to the {spring-boot-gradle-plugin-docs}#packaging-layered-jars -=== Writing the Dockerfile +==== Writing the Dockerfile 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. 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. Here’s how you can launch your jar with a `layertools` jar mode: @@ -8281,7 +8284,7 @@ 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. - +[[using-buildpacks]] === Buildpacks Dockerfiles are just one way to build docker images. Another way to build docker images is directly from your Maven or Gradle plugin, using buildpacks. From 30b5168fed81d3a0dd53af280b8d1902effb280c Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 16 Jul 2020 16:15:50 +0200 Subject: [PATCH 2/2] Polish "Restructure "Building Container Images" section" See gh-22296 --- .../src/docs/asciidoc/deployment.adoc | 2 +- .../src/docs/asciidoc/spring-boot-features.adoc | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc index a7c41e3b30..5590700a56 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc @@ -36,7 +36,7 @@ Once you have unpacked the jar file, you can also get an extra boost to startup NOTE: Using the `JarLauncher` over the application's main method has the added benefit of a predictable classpath order. The jar contains a `classpath.idx` file which is used by the `JarLauncher` when constructing the classpath. -More efficient container images can also be created by <> for your dependencies and application classes and resources (which normally change more frequently). +More efficient container images can also be created by <> for your dependencies and application classes and resources (which normally change more frequently). diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index 1c5c6d59d0..d2ad49ba0d 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -8176,11 +8176,13 @@ If you need the `Mockk` equivalent of the Mockito specific <>, or by <>. +Spring Boot applications can be containerized either by <>, or by <>. -[[building-docker-images]] + + +[[boot-features-container-images-docker]] === Building Docker images A typical Spring Boot fat jar can be converted into a Docker image by adding just a few lines to a Dockerfile that can be used to build the image. However, there are various downsides to copying and running the fat jar as is in the docker image. @@ -8189,6 +8191,8 @@ The other issue is that putting your application's code and all its dependencies Since you probably recompile your code more often than you upgrade the version of Spring Boot you use, it’s often better to separate things a bit more. If you put jar files in the layer before your application classes, Docker often only needs to change the very bottom layer and can pick others up from its cache. + + ==== Layering Docker Images To make it easier to create optimized Docker images that can be built with a dockerfile, Spring Boot supports adding a layer index file to the jar. It provides a list of layers and the parts of the jar that should be contained within them. @@ -8284,7 +8288,7 @@ 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. -[[using-buildpacks]] +[[boot-features-container-images-buildpacks]] === Buildpacks Dockerfiles are just one way to build docker images. Another way to build docker images is directly from your Maven or Gradle plugin, using buildpacks.