mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
Update Dockerfile
This commit is contained in:
parent
b7b5ca185b
commit
a113b6f5e0
1 changed files with 20 additions and 8 deletions
28
Dockerfile
28
Dockerfile
|
@ -1,25 +1,37 @@
|
||||||
# Use an official OpenJDK image as a base
|
#stage 1
|
||||||
FROM openjdk:17-slim
|
# Use a base image with OpenJDK
|
||||||
|
FROM openjdk:17-jdk-slim as build
|
||||||
|
|
||||||
# Set the working directory
|
# Set the working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy the pom.xml and other necessary files first
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Install Maven
|
# Install Maven
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y maven && \
|
apt-get install -y maven && \
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Expose the port
|
# Copy the project files into the container
|
||||||
EXPOSE 8080
|
COPY . .
|
||||||
|
|
||||||
# Run Maven to build the application
|
# Package the application using Maven
|
||||||
RUN ./mvnw package
|
RUN ./mvnw package
|
||||||
|
|
||||||
|
#stage 2
|
||||||
|
# Stage 2: Create a Distroless image
|
||||||
|
FROM gcr.io/distroless/java17
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the packaged JAR from the build stage
|
||||||
|
COPY --from=build /app/target/spring-petclinic-3.3.0-SNAPSHOT.jar app.jar
|
||||||
|
|
||||||
|
#Expose port
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
#cmd command
|
||||||
|
CMD ["app.jar"]
|
||||||
|
|
||||||
|
|
||||||
# Set the command to run the application
|
# Set the command to run the application
|
||||||
|
|
Loading…
Reference in a new issue