Last active
December 27, 2018 20:27
-
-
Save codemwnci/cab2575fafaa902a178a2cebe83b1cf4 to your computer and use it in GitHub Desktop.
Dockerfile for Java/Kotlin Maven Build
This file contains 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
# Part 1: Build the app using Maven | |
FROM maven:3.6.0-jdk-8-alpine | |
## download dependencies | |
ADD pom.xml / | |
RUN mvn verify clean | |
## build after dependencies are down so it wont redownload unless the POM changes | |
ADD . / | |
RUN mvn package | |
# Part 2: use the JAR file used in the first part and copy it across ready to RUN | |
FROM openjdk:8-jdk-alpine | |
WORKDIR /root/ | |
## COPY packaged JAR file and rename as app.jar | |
## → this relies on your MAVEN package command building a jar | |
## that matches *-jar-with-dependencies.jar with a single match | |
COPY --from=0 /target/*-jar-with-dependencies.jar app.jar | |
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","./app.jar"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment