Last active
March 31, 2019 20:38
-
-
Save jeffersonbezerra/0c0c82a7856cc88a18edeb386166873d to your computer and use it in GitHub Desktop.
Dockerfile (Multistage)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM adoptopenjdk/openjdk12:alpine AS builder | |
| MAINTAINER Jefferson Bezerra <[email protected]> | |
| ENV DEMO_APP_FOLDER=/usr/src/app | |
| RUN mkdir -p $DEMO_APP_FOLDER | |
| WORKDIR $DEMO_APP_FOLDER | |
| # add pom.xml only here, and download dependency | |
| RUN apk --no-cache add maven | |
| ADD pom.xml $DEMO_APP_FOLDER | |
| RUN ["mvn", "dependency:go-offline", "clean"] | |
| ADD . $DEMO_APP_FOLDER | |
| RUN ["mvn", "package"] | |
| # --- release --- | |
| FROM adoptopenjdk/openjdk12:alpine-jre AS release | |
| MAINTAINER Jefferson Bezerra <[email protected]> | |
| ENV DEPENDENCY=/usr/src/app/target/dependency | |
| #to work in this way, you need to unpack your jar during the mvn package phase (see maven-dependency-plugin goal unpack) | |
| COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib /app/lib | |
| COPY --from=builder ${DEPENDENCY}/META-INF /app/META-INF | |
| COPY --from=builder ${DEPENDENCY}/BOOT-INF/classes /app | |
| VOLUME /var/log/app | |
| EXPOSE 8080 | |
| WORKDIR /app | |
| ENTRYPOINT ["java","-cp",".:./lib/*","com.example.demo.DemoApplication"] |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the pom.xml file, I configured this plugin in order to unpack the jar file and allow the separated copies of libs e classes. So the image of the libs will be cached, and only changed when the pom.xml be modified.