diff --git a/Dockerfile b/Dockerfile index ceb6b0ab..25b158c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,27 @@ -FROM tomcat -WORKDIR webapps -COPY target/WebApp.war . -RUN rm -rf ROOT && mv WebApp.war ROOT.war -ENTRYPOINT ["sh", "/usr/local/tomcat/bin/startup.sh"] +# Use Maven with OpenJDK 8 as the build stage +FROM maven:3.8.6-openjdk-8 AS base + +WORKDIR /app + +# Copy Maven project files +COPY pom.xml . + +# Download dependencies to cache them +RUN mvn dependency:go-offline + +# Copy application source code +COPY . . + +# Build the WAR file +RUN mvn clean package + +# Use Tomcat as the final runtime image +FROM tomcat:latest + +WORKDIR /usr/local/tomcat/webapps + +# Copy the built WAR file to Tomcat's webapps directory +COPY --from=base /app/target/*.war ./ROOT.war + +# Start Tomcat in the foreground +ENTRYPOINT ["catalina.sh", "run"] diff --git a/Dockerfile1 b/Dockerfile1 new file mode 100644 index 00000000..9f3a5746 --- /dev/null +++ b/Dockerfile1 @@ -0,0 +1,5 @@ +FROM tomcat:latest +WORKDIR webapps +COPY target/WebApp.war . +RUN rm -rf ROOT && mv WebApp.war ROOT.war +ENTRYPOINT ["sh", "/usr/local/tomcat/bin/startup.sh"]