Created
July 12, 2024 13:57
-
-
Save LuisCusihuaman/6061f83fe69d831387cb2fec1662c7a5 to your computer and use it in GitHub Desktop.
Java Dockerfile
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
# Builder stage | |
FROM eclipse-temurin:21-jdk-jammy as builder | |
WORKDIR /opt/app | |
# Copy only the necessary files to download dependencies first and leverage caching | |
COPY gradlew build.gradle settings.gradle ./ | |
COPY gradle ./gradle | |
RUN ./gradlew dependencies --no-daemon || return 0 | |
# Copy the rest of the source files and build the project | |
COPY src ./src | |
RUN ./gradlew build --no-daemon -x test | |
# Runtime stage | |
FROM eclipse-temurin:21-jre-jammy | |
WORKDIR /opt/app | |
EXPOSE 8080 | |
# Copy the built jar from the builder stage | |
COPY --from=builder /opt/app/build/libs/*.jar /opt/app/app.jar | |
# Set the entry point | |
ENTRYPOINT ["java","-Dspring.profiles.active=prod", "-jar", "/opt/app/app.jar"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment