Packaging war file into docker image in multiple layers
This is the way I get a multilayer docker image with a war applicaton.
First open the war file to find out which folders have to be copied to the image:
jar -xf youapp.war
In my project the war file is composed of these folders:
/WEB-INF/META-INF/resources/org
Based on this, I created the following Dockerfile:
FROM openjdk:8-jdk-alpine AS builderWORKDIR target/dependencyARG APPWAR=target/*.warCOPY ${APPWAR} app.warRUN jar -xf ./app.warRUN mv WEB-INF/lib-provided lib-providedRUN mv WEB-INF/lib libFROM openjdk:8-jre-alpineVOLUME /tmpARG DEPENDENCY=target/dependencyCOPY --from=builder ${DEPENDENCY}/lib /app/WEB-INF/libCOPY --from=builder ${DEPENDENCY}/lib-provided /app/WEB-INF/lib-providedCOPY --from=builder ${DEPENDENCY}/org /app/orgCOPY --from=builder ${DEPENDENCY}/resources /app/resourcesCOPY --from=builder ${DEPENDENCY}/META-INF /app/META-INFCOPY --from=builder ${DEPENDENCY}/WEB-INF /app/WEB-INFENTRYPOINT ["java","-cp","/app/WEB-INF/classes:/app/WEB-INF/lib/*:/app/WEB-INF/lib-provided/*","com.company.project.Application"]
I hope it is useful.
Try using the Tomcat Docker image to deploy your warfile. For example:
FROM tomcat:latestCOPY target/demo.war /usr/local/tomcat/webapps/
Reference: