-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
41 lines (29 loc) · 906 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Stage 1: Build the application
FROM gradle:8.10-jdk21 AS build
# Set the working directory
WORKDIR /app
# Copy the Gradle wrapper and build files
COPY gradle /app/gradle
COPY gradlew /app/gradlew
COPY build.gradle.kts /app/build.gradle.kts
COPY settings.gradle.kts /app/settings.gradlekts
# Copy the application source code
COPY src /app/src
# Build the application
RUN ./gradlew bootJar
# Stage 2: Create the final image
FROM eclipse-temurin:21-jre-jammy
# Create a non-root user
RUN useradd -m springuser
# Set the working directory
WORKDIR /app
# Copy the built application from the first stage
COPY --from=build /app/build/libs/*.jar /app/app.jar
# Change ownership of the application files
RUN chown -R springuser:springuser /app
# Switch to the non-root user
USER springuser
# Expose the application port
EXPOSE 8080
# Command to run the application
CMD ["java", "-jar", "/app/app.jar"]