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
- Java 21 base image, copies the JAR, documents 8080, runs
java -jar(Correct option) - Compiles the Java source code inside the image when it is built
- Opens port 8080 on the host automatically when the app runs
- 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 (frommvn package) into the image.EXPOSE 8080: only DOCUMENTS the port; you still needdocker run -p 8080:8080to 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.