Bird
0
0

Consider this Dockerfile snippet:

medium📝 Command Output Q4 of 15
Spring Boot - Docker and Deployment
Consider this Dockerfile snippet:
FROM openjdk:17-jdk-slim
COPY target/app.jar /app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]

What is the expected behavior when you start a container from this image?
AThe app starts but listens on a random port
BThe container starts but immediately exits without running the app
CThe container fails to build due to missing jar file
DThe Spring Boot app starts and listens on port 8080 inside the container
Step-by-Step Solution
Solution:
  1. Step 1: Analyze ENTRYPOINT

    The ENTRYPOINT runs java -jar /app.jar, which starts the Spring Boot application.
  2. Step 2: Check EXPOSE

    Port 8080 is exposed, matching the default Spring Boot port.
  3. Step 3: Confirm COPY

    The jar is copied correctly to /app.jar.
  4. Final Answer:

    The Spring Boot app starts and listens on port 8080 inside the container -> Option D
  5. Quick Check:

    ENTRYPOINT runs app, EXPOSE matches app port [OK]
Quick Trick: ENTRYPOINT runs app; EXPOSE declares port [OK]
Common Mistakes:
  • Assuming EXPOSE publishes ports externally
  • Confusing ENTRYPOINT with CMD
  • Ignoring correct jar path

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes