Building images without a Dockerfile

Docker · lesson 22 of 31 · 4 min read

Use Jib or Spring Boot buildpacks to get layered, reproducible images straight from Maven.

Open this lesson in the learning hub

Key points

  • mvn spring-boot:build-image uses Cloud Native Buildpacks: no Dockerfile, sane defaults, but it needs a Docker daemon.
  • Jib builds and pushes straight from Maven with no Docker daemon at all, which makes locked-down CI runners much simpler.
  • Both split the app into layers - dependencies, snapshot dependencies, resources, then classes - so a code change re-pushes kilobytes.
  • They are reproducible on purpose: file timestamps are zeroed, so the same source produces the same digest twice.
  • You trade away control. Native packages, an odd base or a custom entrypoint still want a hand-written multi-stage Dockerfile.
  • Staying with a Dockerfile? Spring Boot can still split the jar: java -Djarmode=tools -jar app.jar extract --layers.

Example

# buildpacks - part of the Spring Boot plugin, no extra config
mvn spring-boot:build-image -Dspring-boot.build-image.imageName=acme/myapp:1.0

# Jib - builds and pushes with no local Docker daemon
#   <plugin>
#     <groupId>com.google.cloud.tools</groupId>
#     <artifactId>jib-maven-plugin</artifactId>
#     <configuration>
#       <from><image>eclipse-temurin:21-jre</image></from>
#       <to><image>ghcr.io/acme/myapp:1.0</image></to>
#       <container><user>10001</user><ports><port>8080</port></ports></container>
#     </configuration>
#   </plugin>
mvn compile jib:build            # straight to the registry
mvn compile jib:dockerBuild      # into the local daemon instead

If your Dockerfile is only FROM plus COPY jar, a plugin will do it better.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Docker course, and every lesson in it is listed on the Docker contents page.