Skip to content

Instantly share code, notes, and snippets.

@adam-sandor
Created July 2, 2021 10:25
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 adam-sandor/9c87cc743392bfe5e778c4486a097154 to your computer and use it in GitHub Desktop.
Save adam-sandor/9c87cc743392bfe5e778c4486a097154 to your computer and use it in GitHub Desktop.
Multistage Docker build with Maven
FROM maven:3 AS build
WORKDIR /build
COPY pom.xml .
RUN mkdir -p src/main/java
COPY FakeMain.java src/main/java #without this mvn package will fail
RUN mvn package
COPY src ./src
RUN mvn package
FROM openjdk:10.0.1-10-jre
WORKDIR /app
COPY --from=build /build/target/myservice.jar .
CMD java -jar myservice.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment