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
+13-15Lines changed: 13 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -8222,24 +8222,17 @@ If you need the `Mockk` equivalent of the Mockito specific <<boot-features-testi
8222
8222
8223
8223
8224
8224
[[boot-features-container-images]]
8225
-
== Building Container Images
8226
-
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>>.
8227
-
8228
-
8229
-
8230
-
[[boot-features-container-images-docker]]
8231
-
=== Building Docker images
8232
-
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.
8225
+
== Container Images
8226
+
It is easily possible to package a Spring Boot fat jar as a docker image.
8233
8227
However, there are various downsides to copying and running the fat jar as is in the docker image.
8234
8228
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.
8235
8229
The other issue is that putting your application's code and all its dependencies in one layer in the Docker image is sub-optimal.
8236
8230
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.
8237
8231
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.
8238
8232
8239
-
8240
-
8241
-
==== Layering Docker Images
8242
-
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.
8233
+
[[boot-layering-docker-images]]
8234
+
=== Layering Docker Images
8235
+
To make it easier to create optimized Docker images, Spring Boot supports adding a layer index file to the jar.
8243
8236
It provides a list of layers and the parts of the jar that should be contained within them.
8244
8237
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.
8245
8238
Out-of-the-box, the following layers are supported:
@@ -8273,9 +8266,12 @@ Application code is more likely to change between builds so it is isolated in a
8273
8266
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.
8274
8267
For Gradle, refer to the {spring-boot-gradle-plugin-docs}#packaging-layered-jars[packaging layered jars section] of the Gradle plugin documentation.
8275
8268
8269
+
=== Building Container Images
8270
+
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>>.
8276
8271
8277
-
8278
-
==== Writing the Dockerfile
8272
+
[[boot-features-container-images-docker]]
8273
+
==== Dockerfiles
8274
+
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.
8279
8275
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.
8280
8276
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.
8281
8277
@@ -8338,7 +8334,7 @@ You can use some combination of `unzip` and `mv` to move things to the right lay
8338
8334
8339
8335
8340
8336
[[boot-features-container-images-buildpacks]]
8341
-
=== Buildpacks
8337
+
==== Cloud Native Buildpacks
8342
8338
Dockerfiles are just one way to build docker images.
8343
8339
Another way to build docker images is directly from your Maven or Gradle plugin, using buildpacks.
8344
8340
If you’ve ever used an application platform such as Cloud Foundry or Heroku then you’ve probably used a buildpack.
@@ -8351,6 +8347,8 @@ This means you can just type a single command and quickly get a sensible image i
8351
8347
8352
8348
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].
8353
8349
8350
+
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.
0 commit comments