liveBook · Manning

Container image

As explained in Spring in Action, Sixth Edition

A container image is an immutable package containing an application's filesystem, runtime dependencies, metadata, and startup configuration for creating containers.

A container image is an immutable package for an application, its runtime, filesystem, metadata, and startup configuration. Containers created from the image use a common format that can run across supported environments. section 18.3

For a Spring Boot application, the image can contain an executable JAR and a Java runtime. This makes it suitable for cloud platforms and Kubernetes, where the image becomes the deployable unit. section 18.1 section 18.3

Packaging a Spring Boot JAR

A Dockerfile can select an OpenJDK 11 runtime, locate the JAR in target/, copy it to app.jar, and configure java -jar /app.jar as the startup command. Building the Dockerfile produces a tagged image; running that image can publish the application on port 8080. section 18.3

FROM openjdk:11.0.12-jre
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Shows the complete Dockerfile for turning a Maven-built executable JAR into a runnable image. section 18.3

Spring Boot can also build the image through Maven or Gradle with build-image or bootBuildImage. Image names can be supplied on the command line or configured in the build plugin, after which Docker can run or push the image.

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains Dockerfile construction, image building, running, naming, and pushing, but stops short of orchestration configuration.
Examples
Uses an OpenJDK 11 Dockerfile, a target/*.jar artifact, Docker build and run commands, and Spring Boot image-build tasks.
What it assumes
Assumes an executable Spring Boot JAR and introduces Dockerfile instructions, image commands, and Spring Boot image-build tasks.
What you can do after
Build it from scratch with Docker or Spring Boot Maven and Gradle tasks, then run, name, and push the resulting image.
How it connects
Connects executable JAR files, Dockerfiles, Docker, Spring Boot, Maven, Gradle, cloud platforms, and Kubernetes.

Also explained in

Compare how 25 books explain container image →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.