created a dockerfile with single and multi step builds

This commit is contained in:
GasparAM 2023-04-11 14:45:15 +04:00
parent 051e40477f
commit ba1fbbf0e5

24
Dockerfile Normal file
View file

@ -0,0 +1,24 @@
# Create Dockerfile for Spring-petclinic application using pre-built artifact
# FROM alpine:latest
# ENV JAR=spring-petclinic-3.0.3.jar
# RUN apk --no-cache add openjdk17-jre-headless
# COPY ./target/${JAR} ./
# EXPOSE 8080
# CMD ["/bin/sh", "-c", "/usr/bin/java -jar ${JAR}"]
# Create multi-stage Dockerfile for Spring-petclinic application
FROM alpine:latest AS builder
RUN apk --no-cache add openjdk17
WORKDIR /tmp
COPY ./ ./
RUN ./mvnw clean ; ./mvnw package
FROM alpine:latest
ENV JAR=spring-petclinic-3.0.3.jar
RUN apk --no-cache add openjdk17-jre-headless
WORKDIR /home
COPY --from=builder /tmp/target/spring-*.jar ./
EXPOSE 8080
CMD ["/bin/sh", "-c", "/usr/bin/java -jar /home/spring-*.jar"]