From 4dde03c6c2829d23793b2ddba4bc21f50891696c Mon Sep 17 00:00:00 2001 From: Hemanth <81347482+HemanthGangula@users.noreply.github.com> Date: Fri, 15 Mar 2024 07:25:59 +0530 Subject: [PATCH] Update Dockerfile By separating build and runtime environments, it significantly reduces the final image size, leading to faster deployments and resource efficiency. --- Dockerfile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index f7cd959..baa7564 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,13 @@ -FROM openjdk:8 +# Stage 1: Build the application +FROM maven:3.8.4 AS build +WORKDIR /app +COPY pom.xml . +COPY src ./src +RUN mvn package -DskipTests + +# Stage 2: Package the application into a smaller image +FROM openjdk:8-jre-slim +WORKDIR /app +COPY --from=build /app/target/springboot-images-new.jar . EXPOSE 8080 -ADD target/springboot-images-new.jar springboot-images-new.jar -ENTRYPOINT ["java","-jar","/springboot-images-new.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "springboot-images-new.jar"]