liveBook · Manning

Docker build

As explained in Spring in Action, Sixth Edition

docker build is a Docker command that constructs a container image from a Dockerfile and its build context.

docker build constructs a container image from a Dockerfile and its build context. A typical Spring Boot workflow packages an executable JAR, copies it into an image, and defines the command that runs when a 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"]

Use this Dockerfile to base the image on an OpenJDK 11 runtime, select the project JAR, copy it as app.jar, and launch it with java -jar. section 18.3

Build a Taco Cloud image

From the Maven project root, run docker build . -t habuma/tacocloud:0.0.19-SNAPSHOT. The dot supplies the Dockerfile's location and build context; replace it with another path when running the command elsewhere. section 18.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains Dockerfile instructions line by line and demonstrates tagged builds, without detailing Docker image internals.
Examples
Uses an OpenJDK 11 Dockerfile, a target/*.jar artifact, and a tagged Taco Cloud image build.
What it assumes
Assumes a Dockerfile and executable JAR in the Maven target directory.
What you can do after
Builds a tagged Docker image from a Spring Boot project's Dockerfile and build context.
How it connects
Connects Dockerfile, build context, executable JAR, container image, Docker, and Spring Boot deployment.

Also explained in

Compare how 4 books explain docker build →

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.