You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc
+14-16Lines changed: 14 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -2829,7 +2829,7 @@ For machine clients, it produces a JSON response with details of the error, the
2829
2829
For browser clients, there is a "`whitelabel`" error view that renders the same data in HTML format (to customize it, add a `View` that resolves to `error`).
2830
2830
2831
2831
There are a number of `server.error` properties that can be set if you want to customize the default error handling behavior.
2832
-
See the <<appendix-application-properties.adoc#common-application-properties-server, "`Server Properties`">> section of the Appendix.
2832
+
See the <<appendix-application-properties.adoc#common-application-properties-server, "`Server Properties`">> section of the Appendix.
2833
2833
2834
2834
To replace the default behavior completely, you can implement `ErrorController` and register a bean definition of that type or add a bean of type `ErrorAttributes` to use the existing mechanism but replace the contents.
2835
2835
@@ -8825,24 +8825,17 @@ If you need the `Mockk` equivalent of the Mockito specific <<boot-features-testi
8825
8825
8826
8826
8827
8827
[[boot-features-container-images]]
8828
-
== Building Container Images
8829
-
Spring Boot applications can be containerized either by <<boot-features-container-images-docker,packaging them into Docker images>>, or by <<boot-features-container-images-buildpacks,using Buildpacks to create Docker compatible container images that you can run anywhere>>.
8830
-
8831
-
8832
-
8833
-
[[boot-features-container-images-docker]]
8834
-
=== Building Docker images
8835
-
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.
8828
+
== Container Images
8829
+
It is easily possible to package a Spring Boot fat jar as a docker image.
8836
8830
However, there are various downsides to copying and running the fat jar as is in the docker image.
8837
8831
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.
8838
8832
The other issue is that putting your application's code and all its dependencies in one layer in the Docker image is sub-optimal.
8839
8833
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.
8840
8834
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.
8841
8835
8842
-
8843
-
8844
-
==== Layering Docker Images
8845
-
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.
8836
+
[[boot-layering-docker-images]]
8837
+
=== Layering Docker Images
8838
+
To make it easier to create optimized Docker images, Spring Boot supports adding a layer index file to the jar.
8846
8839
It provides a list of layers and the parts of the jar that should be contained within them.
8847
8840
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.
8848
8841
Out-of-the-box, the following layers are supported:
@@ -8876,9 +8869,12 @@ Application code is more likely to change between builds so it is isolated in a
8876
8869
For Maven, refer to the {spring-boot-maven-plugin-docs}#repackage-layers[packaging layered jars section] for more details on adding a layer index to the jar.
8877
8870
For Gradle, refer to the {spring-boot-gradle-plugin-docs}#packaging-layered-jars[packaging layered jars section] of the Gradle plugin documentation.
8878
8871
8872
+
=== Building Container Images
8873
+
Spring Boot applications can be containerized <<boot-features-container-images-docker,using Dockerfiles>>, or by <<boot-features-container-images-buildpacks,using Cloud Native Buildpacks to create docker compatible container images that you can run anywhere>>.
8879
8874
8880
-
8881
-
==== Writing the Dockerfile
8875
+
[[boot-features-container-images-docker]]
8876
+
==== Dockerfiles
8877
+
While it is possible to convert a Spring Boot fat jar into a docker image with just a few lines in the Dockerfile, we will use the <<boot-layering-docker-images,layering feature>> to create an optimized docker image.
8882
8878
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.
8883
8879
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.
8884
8880
@@ -8941,7 +8937,7 @@ You can use some combination of `unzip` and `mv` to move things to the right lay
8941
8937
8942
8938
8943
8939
[[boot-features-container-images-buildpacks]]
8944
-
=== Buildpacks
8940
+
==== Cloud Native Buildpacks
8945
8941
Dockerfiles are just one way to build docker images.
8946
8942
Another way to build docker images is directly from your Maven or Gradle plugin, using buildpacks.
8947
8943
If you’ve ever used an application platform such as Cloud Foundry or Heroku then you’ve probably used a buildpack.
@@ -8954,6 +8950,8 @@ This means you can just type a single command and quickly get a sensible image i
8954
8950
8955
8951
Refer to the individual plugin documentation on how to use buildpacks with {spring-boot-maven-plugin-docs}#build-image[Maven] and {spring-boot-gradle-plugin-docs}#build-image[Gradle].
8956
8952
8953
+
NOTE: The https://github.com/paketo-buildpacks/spring-boot[Paketo Spring Boot buildpack] has also been updated to support the `layers.idx` file so any customization that is applied to it will be reflected in the image created by the buildpack.
8954
+
8957
8955
NOTE: In order to achieve reproducible builds and container image caching, Buildpacks can manipulate the application resources metadata (such as the file "last modified" information).
8958
8956
You should ensure that your application does not rely on that metadata at runtime.
8959
8957
Spring Boot can use that information when serving static resources, but this can be disabled with configprop:spring.web.resources.cache.use-last-modified[]
0 commit comments