0
0
Spring Bootframework~20 mins

Dockerfile for Spring Boot in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spring Boot Docker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Docker build command
You have this Dockerfile for a Spring Boot app:
FROM openjdk:17-jdk-slim
COPY target/app.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]

What will be the output of docker build -t springboot-app . if the target/app.jar file is missing?
ASuccessfully builds the image with tag springboot-app
BBuild completes but image is empty
CWarning about missing file but image builds
DError: COPY failed: stat target/app.jar: no such file or directory
Attempts:
2 left
💡 Hint
Think about what happens if the file to copy does not exist during build.
Configuration
intermediate
2:00remaining
Correct Dockerfile for multi-stage build
Which Dockerfile correctly uses a multi-stage build to compile a Spring Boot app with Maven and produce a minimal final image?
A
FROM maven:3.8.6-openjdk-17
COPY . /app
WORKDIR /app
RUN mvn clean package
ENTRYPOINT ["java", "-jar", "target/app.jar"]
B
FROM maven:3.8.6-openjdk-17 AS build
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests
FROM openjdk:17-jdk-slim
COPY --from=build /app/target/app.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
C
FROM openjdk:17-jdk-slim
COPY target/app.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
D
FROM openjdk:17-jdk-slim
RUN mvn clean package
COPY target/app.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
Attempts:
2 left
💡 Hint
Multi-stage builds separate build environment and runtime environment.
Troubleshoot
advanced
2:00remaining
Why does the Spring Boot app fail to start in Docker?
You built a Docker image for your Spring Boot app but when running the container, it exits immediately with no logs. The Dockerfile is:
FROM openjdk:17-jdk-slim
COPY target/app.jar app.jar
ENTRYPOINT java -jar app.jar

What is the most likely cause?
AThe base image openjdk:17-jdk-slim does not support Spring Boot
BThe app.jar file is missing in the image
CENTRYPOINT should be an array of strings, not a single string
DThe container needs environment variables to start
Attempts:
2 left
💡 Hint
How Docker interprets ENTRYPOINT differs between string and array syntax.
🔀 Workflow
advanced
2:00remaining
Order of steps to build and run Spring Boot Docker container
Put these steps in the correct order to build and run a Spring Boot app Docker container:
1. Run the container with docker run
2. Write the Dockerfile
3. Build the jar with Maven
4. Build the Docker image with docker build
A1,2,3,4
B2,1,3,4
C1,3,2,4
D2,3,1,4
Attempts:
2 left
💡 Hint
Think about what you need before building the image and running the container.
Best Practice
expert
2:00remaining
Best practice for reducing Spring Boot Docker image size
Which option is the best practice to reduce the size of a Spring Boot Docker image?
AUse a multi-stage build with Maven and copy only the jar to a slim OpenJDK base image
BUse the full OpenJDK image and copy all source code into the image
CBuild the jar inside the container every time it runs
DUse a base image with JRE instead of JDK and copy the jar
Attempts:
2 left
💡 Hint
Think about separating build and runtime environments.