generated from ibm-developer-skills-network/coding-project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
41 lines (30 loc) · 853 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
# Build stage
FROM eclipse-temurin:21-jdk-jammy AS build
WORKDIR /app
# Copy maven files first to cache dependencies
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
# Make the mvnw script executable
RUN chmod +x mvnw
# Download dependencies
RUN ./mvnw dependency:go-offline -B
# Copy source code
COPY src src
# Build the application
RUN ./mvnw package -DskipTests
# Runtime stage
FROM eclipse-temurin:21-jre-jammy
WORKDIR /app
# Copy the built artifact from build stage
COPY --from=build /app/target/*.jar app.jar
# Create a non-root user
RUN groupadd -r spring && useradd -r -g spring spring
USER spring:spring
# Set the entrypoint
ENTRYPOINT ["java", "-jar", "app.jar"]
# Document that the container listens on port 8080
EXPOSE 8080
# Add health check
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:8080/health || exit 1