Spring Boot provides two first-class approaches to container image creation: Cloud Native Buildpacks for a zero-Dockerfile workflow, and layered JAR Dockerfiles for full control over image construction. Both approaches produce efficient, cache-friendly OCI images that run on any container runtime.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
Cloud Native Buildpacks
Cloud Native Buildpacks (CNB) transform your application source or JAR into a runnable OCI image without requiring you to write a Dockerfile. Spring Boot’s Maven and Gradle plugins include built-in buildpack support, so a single command produces a sensible image and loads it into your local Docker daemon.The Paketo Spring Boot buildpack supports the
layers.idx file, so any layer customization applied to your JAR will be reflected in the image the buildpack creates.To achieve reproducible builds and container image caching, buildpacks may manipulate application resource metadata such as file “last modified” timestamps. Ensure your application does not rely on that metadata at runtime. Spring Boot uses this information when serving static resources, which can be disabled with the
spring.web.resources.cache.use-last-modified property.Verify Docker is running
Buildpacks require a running Docker daemon. Confirm it is accessible before proceeding.
Build the image
Run the build-image goal or task from your project root. Spring Boot’s plugin contacts the Paketo builder, compiles your application, and loads the resulting image into Docker — no Dockerfile required.
- Maven
- Gradle
Dockerfiles with layered JARs
Writing your own Dockerfile gives you precise control over image layers and lets you integrate AOT cache or CDS for faster startup. Spring Boot’s layering feature splits the application into stable and frequently-changing layers so Docker’s build cache is used as effectively as possible.Why layering matters
Packaging an uber JAR directly into a single Docker layer is simple but wasteful. Library code changes far less often than application code, yet both end up in the same layer. With layered JARs, Spring Boot separates the JAR contents into four standard layers:| Layer | Contents |
|---|---|
dependencies | Released library JARs |
spring-boot-loader | Spring Boot loader classes |
snapshot-dependencies | Snapshot library JARs |
application | Your application classes and resources |
application layer while the three dependency layers are pulled from cache.
Example layers.idx
Building with a Dockerfile
Inspect available jarmode commands
The This prints the available commands:
spring-boot-jarmode-tools JAR is automatically added to your repackaged JAR. Use it to explore the extraction options:Write the Dockerfile
Use a multi-stage build. The first stage (
builder) extracts the layered JAR, and the second stage copies each layer in dependency order so Docker can cache them independently.- Standard (JVM)
- With AOT cache (Java 24+)
- With CDS (Java < 24)
If you are using Java 24 or later, use the AOT cache tab. For Java versions below 24, AOT cache is unavailable — use CDS instead.
Efficient deployments with extracted JARs
Running the application directly from the nested-JAR uber JAR adds a small startup overhead due to classloading from nested archives. For production deployments, extracting the JAR first is recommended.Approach comparison
Cloud Native Buildpacks
No Dockerfile required. Single command build. Automatic base image selection and security patching. Best for teams that want a managed, opinionated pipeline.
Layered JAR Dockerfile
Full control over base image and build steps. Supports AOT cache and CDS training runs inline. Best for teams with existing Docker workflows or specific image requirements.