Skip to content

Instantly share code, notes, and snippets.

@codemwnci
Last active December 27, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codemwnci/cab2575fafaa902a178a2cebe83b1cf4 to your computer and use it in GitHub Desktop.
Save codemwnci/cab2575fafaa902a178a2cebe83b1cf4 to your computer and use it in GitHub Desktop.
Dockerfile for Java/Kotlin Maven Build
# 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