From a113b6f5e0b3c42c23808f26daccc6378d661abb Mon Sep 17 00:00:00 2001 From: Rajesh1b <118235010+Rajesh1b@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:51:23 +0530 Subject: [PATCH] Update Dockerfile --- Dockerfile | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20a007f7e..4258f2e0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,37 @@ -# Use an official OpenJDK image as a base -FROM openjdk:17-slim +#stage 1 +# Use a base image with OpenJDK +FROM openjdk:17-jdk-slim as build # Set the working directory WORKDIR /app -# Copy the pom.xml and other necessary files first -COPY . . - # Install Maven RUN apt-get update && \ apt-get install -y maven && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Expose the port -EXPOSE 8080 +# Copy the project files into the container +COPY . . -# Run Maven to build the application +# Package the application using Maven RUN ./mvnw package +#stage 2 +# Stage 2: Create a Distroless image +FROM gcr.io/distroless/java17 +# Set the working directory +WORKDIR /app + +# Copy the packaged JAR from the build stage +COPY --from=build /app/target/spring-petclinic-3.3.0-SNAPSHOT.jar app.jar + +#Expose port +EXPOSE 8080 + +#cmd command +CMD ["app.jar"] # Set the command to run the application