Spring / Spring Boot 4 Basics Interview Questions
How does Spring Boot 4 support containerised deployments with Docker?
Spring Boot 4 has first-class container support via Cloud Native Buildpacks (CNB), Layered JARs, and GraalVM native image Docker images. The Spring Boot Maven/Gradle plugins can produce optimised Docker images without a Dockerfile.
# Option 1: Buildpacks (recommended -- no Dockerfile needed) # Maven: ./mvnw spring-boot:build-image # Produces: docker.io/library/order-service:1.0.0 # With custom image name and registry: ./mvnw spring-boot:build-image \ -Dspring-boot.build-image.imageName=gcr.io/my-project/order-service:1.0.0 # Native image with Buildpacks: ./mvnw spring-boot:build-image -Pnative # Option 2: Traditional Dockerfile with Layered JAR # First, enable layered JAR: <configuration> <layers> <enabled>true</enabled> </layers> </configuration> # Dockerfile (multi-stage, layered JAR): FROM eclipse-temurin:17-jre AS builder WORKDIR /app COPY target/*.jar app.jar RUN java -Djarmode=tools -jar app.jar extract --layers --launcher FROM eclipse-temurin:17-jre WORKDIR /app # Copy layers in order of least-to-most frequently changed: COPY --from=builder /app/extracted/dependencies ./ COPY --from=builder /app/extracted/spring-boot-loader ./ COPY --from=builder /app/extracted/snapshot-dependencies ./ COPY --from=builder /app/extracted/application ./ EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"] # Docker Compose for local development: # compose.yml (Spring Boot 4 auto-detects compose.yml): services: postgres: image: postgres:17 environment: POSTGRES_DB: orders POSTGRES_USER: dev POSTGRES_PASSWORD: dev ports: ["5432:5432"] redis: image: redis:8 ports: ["6379:6379"] # spring.docker.compose.enabled=true (default) auto-starts compose services
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
