Skip to main content
PreparationZone Logo
PrepZone

Containerizing and Deploying Boot Apps

Dockerfiles, health probes, graceful shutdown and Kubernetes deployment.

Pass checkpoint below

Read these first

Why this matters

  • "Works on my machine" disappears when the same Docker image runs in dev, staging, and production — only environment variables change.
  • Kubernetes rolling updates deploy new BookStore versions with zero downtime by gradually replacing pods while readiness probes gate traffic.
  • Graceful shutdown ensures in-flight checkout requests complete before the pod terminates, preventing lost orders during deploys.

Container image

L1 · Fresher

Package Boot JAR in a distroless or slim JRE image; run as non-root user.

Health probes

L2 · Intermediate

Wire liveness/readiness to actuator health groups that include database checks.

Resources limits

L3 · Advanced

Set CPU/memory requests and limits based on load tests — JVM needs headroom for GC.

12-factor config

L4 · Expert

Inject config via env vars and secrets; never bake environment-specific URLs into images.

StreamHub production architecture (AWS)

HTTPSstaticmissAPICLIENT
Mobile / WebStreamHub cli…
NETWORK
Route 53GeoDNS routing
NETWORK
CloudFrontCDN + WAF edge
NETWORK
AWS ALBTLS terminati…
NETWORK
API GatewayJWT · rate li…
STORAGE
Amazon S3media origin
COMPUTE
Amazon EKSAPI · auth · …
DATABASE
ElastiCachesessions · ho…
DATABASE
RDS Postgresprimary + rep…
INTEGRATION
Amazon MSKdomain events
ANALYTICS
OpenSearchstream discov…
OPS
CloudWatchmetrics · X-R…
End-to-end path from user to data — reference this when placing any new service.

Deployment essentials

  • Multi-stage Dockerfile — build with Maven in one stage, run a slim JRE image in the final stage.
  • Liveness probe — restarts the pod if the JVM is wedged; hits /actuator/health/liveness.
  • Readiness probe — removes the pod from load balancing until it can serve traffic.
  • Resource limits — requests and limits for CPU and memory prevent one pod from starving the node.
  • Graceful shutdown — server.shutdown: graceful + terminationGracePeriodSeconds let requests drain.

Production Dockerfile

Java
# Build stage
FROM eclipse-temurin:21-jdk-alpine AS build
WORKDIR /app
COPY mvnw pom.xml ./
COPY .mvn .mvn
RUN ./mvnw dependency:go-offline -B
COPY src ./src
RUN ./mvnw package -DskipTests -B

# Runtime stage
FROM eclipse-temurin:21-jre-alpine
RUN addgroup -S bookstore && adduser -S bookstore -G bookstore
WORKDIR /app
COPY --from=build /app/target/bookstore-api-*.jar app.jar
USER bookstore
EXPOSE 8080

ENTRYPOINT ["java", \
    "-XX:+UseContainerSupport", \
    "-XX:MaxRAMPercentage=75.0", \
    "-Djava.security.egd=file:/dev/./urandom", \
    "-jar", "app.jar"]

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 3 sections

  • Graceful shutdown configuration
  • Kubernetes deployment manifest
  • Build and deploy pipeline

Test yourself

Answer these before moving on — recall is what makes it stick.