Use multi-stage builds
# Code template to get you started For Multistage Dockerfile
# Build stage with development tools
FROM maven:3.5-jdk-8 as build
WORKDIR /app
COPY . .
RUN mvn clean package
#FInal Stage
FROM tomcat:8.0.20-jre8
COPY --from=build /app/target/maven-web-app*.war /usr/local/tomcat/webapps/maven-web-application.war
What is an Multistage Dockerfile?
Docker has revolutionized the world of software development and software deployment by simplifying the process of creating, distributing, and running applications within containers. This feature of Docker is very helpful for developers, so Among Docker’s sea of features, multistage Dockerfile stands out as a very powerful tool for optimizing the size and efficiency of container images Let’s get familiar with multistage Dockerfiles and add another tool to our journey with DevOps.