Repaso
Español
Cloud & DevOpsIntermediateOPS-41

What does this Dockerfile for a Spring Boot app do?

FROM eclipse-temurin:21-jre
WORKDIR /app
COPY target/app.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

Options

  1. Java 21 base image, copies the JAR, documents 8080, runs java -jar (Correct option)
  2. Compiles the Java source code inside the image when it is built
  3. Opens port 8080 on the host automatically when the app runs
  4. Installs Maven and runs the tests when the image is being built

Answer

Starts from a base image with Java 21, copies the built JAR, documents port 8080 and runs the app with java -jar

Why

Line by line:

  • FROM: start from an existing image that contains a Java 21 runtime (JRE, enough to run, smaller than the JDK).
  • WORKDIR: working folder inside the image.
  • COPY: put the already built JAR (from mvn package) into the image.
  • EXPOSE 8080: only DOCUMENTS the port; you still need docker run -p 8080:8080 to publish it.
  • ENTRYPOINT: the command that runs when the container starts.

It does not compile anything; a multi-stage build can do the Maven build in a first stage.

Remember

EXPOSE documents the port; -p publishes it.

Key terms

Practice this question in Repaso