liveBook · Manning

Dockerfile

As explained in Spring in Action, Sixth Edition

A Dockerfile is a text configuration file containing instructions for building a container image.

A Dockerfile is a text configuration file that describes how to create a container image for an application. A basic Spring Boot recipe starts with an OpenJDK 11 runtime, copies the built executable JAR, and runs it when the container starts. section 18.3

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

This four-line recipe defines the runtime base, locates the project JAR, copies it as app.jar, and declares the startup command. section 18.3

The recipe connects each instruction to the image-building workflow:

  • FROM selects a predefined image providing the OpenJDK 11 Java runtime. section 18.3
  • ARG JAR_FILE uses target/*.jar so the definition does not depend on a specific JAR name or version. section 18.3
  • COPY places the built JAR in the image under the generic name app.jar. section 18.3
  • ENTRYPOINT runs java -jar /app.jar when a container created from the image starts. section 18.3

Build and run the image

After building the application JAR, run docker build . -t habuma/tacocloud:0.0.19-SNAPSHOT, then start it with docker run -p8080:8080 habuma/tacocloud:0.0.19-SNAPSHOT. section 18.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains a minimal four-instruction Dockerfile line by line and demonstrates Docker build and run commands.
Examples
Uses an OpenJDK 11 image, target/*.jar, app.jar, and tacocloud Docker build and run commands.
What it assumes
Assumes a built executable JAR in target/ and introduces the Dockerfile instructions needed to package and start it.
What you can do after
Operate Docker CLI commands to build an image from a Dockerfile and run the packaged application on port 8080.
How it connects
Connects Dockerfile instructions with container images, executable JAR files, Docker CLI, and container entry points.

Also explained in

Compare how 18 books explain Dockerfile →

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.