Skip to content

Instantly share code, notes, and snippets.

@vvillschneider
Last active January 28, 2022 02:24
Show Gist options
  • Save vvillschneider/44a32984bf922c88b2dc38f305b007f8 to your computer and use it in GitHub Desktop.
Save vvillschneider/44a32984bf922c88b2dc38f305b007f8 to your computer and use it in GitHub Desktop.
Multi-step Dockerfile for Java project with Gradle
FROM openjdk:17-oracle AS BUILD_IMAGE
ENV BASE_DIRECTORY=/app/
WORKDIR $BASE_DIRECTORY
COPY build.gradle settings.gradle gradlew $BASE_DIRECTORY
COPY gradle $BASE_DIRECTORY/gradle
RUN ./gradlew build --stacktrace || return 0
COPY src $BASE_DIRECTORY/src
RUN ./gradlew build --stacktrace
FROM openjdk:17-oracle
ENV BASE_DIRECTORY=/app/
WORKDIR $BASE_DIRECTORY
COPY --from=BUILD_IMAGE $BASE_DIRECTORY/build/libs/main-service.jar .
EXPOSE 8080
ENTRYPOINT ["java","-jar","main-service.jar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment