# Multi-stage build for Java 17 Spring Boot application # Build stage FROM maven:3.9-eclipse-temurin-17-alpine AS build WORKDIR /build # Copy pom.xml and download dependencies (cached layer) COPY pom.xml . RUN mvn dependency:go-offline -B # Copy source and build COPY src ./src RUN mvn clean package -DskipTests -B # Runtime stage FROM eclipse-temurin:17-jre-alpine WORKDIR /app # Create non-root user RUN addgroup -g 1000 appuser && \ adduser -D -u 1000 -G appuser appuser # Copy JAR from build stage COPY --from=build /build/target/*.jar application.jar # Change ownership RUN chown -R appuser:appuser /app # Switch to non-root user USER appuser # Expose application port EXPOSE 8080 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1 # Run application ENTRYPOINT ["java", "-jar", "application.jar"]