diff --git a/Dockerfile b/Dockerfile index 8b1378917..b84a1205d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,27 @@ +# Use a base image with Java and Maven installed +FROM maven:3.8.4-openjdk-17-slim AS builder +# Set the working directory in the container +WORKDIR /app + +# Copy the Maven project files +COPY pom.xml . +COPY src ./src + +# Build the application +RUN mvn clean package -DskipTests + +# Use a lightweight base image for the application +FROM openjdk:17-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the compiled application from the builder stage +COPY --from=builder /app/target/spring-petclinic*.jar ./app.jar + +# Expose the port on which the application will run +EXPOSE 8080 + +# Define the command to run the application when the container starts +CMD ["java", "-jar", "app.jar"]