Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ajeetraina/6cc6c98db88b63dc4dfe17c5798074aa to your computer and use it in GitHub Desktop.
Save ajeetraina/6cc6c98db88b63dc4dfe17c5798074aa to your computer and use it in GitHub Desktop.
# Dockerfile (for both Linux and Windows)
ARG DOCKER_OS=linux # Default OS (can be overridden during build)
FROM eclipse-temurin:21-jdk-jammy
WORKDIR /app
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
# Install dos2unix conditionally based on OS
RUN IF [ "${DOCKER_OS}" = "windows" ]; THEN apt-get update && apt-get install -y dos2unix; FI
# Convert line endings conditionally (assuming dos2unix is installed)
RUN IF [ "${DOCKER_OS}" = "windows" ]; THEN dos2unix .; FI
# Rest of the multi-stage build instructions...
FROM base as development
CMD ["./mvnw", "spring-boot:run", "-Dspring-boot.run.profiles=mysql", "-Dspring-boot.run.jvmArguments='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000'"]
FROM base as build
RUN ./mvnw package
FROM eclipse-temurin:21-jre-jammy as production
EXPOSE 8080
COPY --from=build /app/target/spring-petclinic-*.jar /spring-petclinic.jar
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/spring-petclinic.jar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment