Hello to all the readers!
There is multi stage build in which the build time and run time dependencies are separated.
For example JDK is required to build java app but JDK is not required in final image to be run.
FROM maven AS build
WORKDIR /app
COPY . .
RUN mvn package
FROM tomcat
COPY --from=build /app/target/file.war /usr/local/tomcat/webapps
We copy only executable files from build stage that has to run thereby reducing the docker image size.