# Stage 1: Build stage FROM maven:3.9-eclipse-temurin-21 AS build # Set the working directory inside the container WORKDIR /app # Copy the pom.xml and dependencies (helps in caching dependencies) COPY pom.xml . # Download dependencies (this will cache dependencies in the Docker layer) RUN mvn dependency:go-offline # Copy the rest of the application source code COPY src ./src # Build the Spring Boot app RUN mvn clean package # Stage 2: Run stage FROM eclipse-temurin:21-jdk AS runtime # Copy the built JAR file from the build stage COPY --from=build /app/target/*.jar /app/app.jar # Expose the default Spring Boot port EXPOSE 8080 # Command to run the Spring Boot application ENTRYPOINT ["java", "-jar", "/app/app.jar"]