-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
42 lines (28 loc) · 965 Bytes
/
Copy pathDockerfile
File metadata and controls
42 lines (28 loc) · 965 Bytes
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
42
# Multi-stage build for smaller image size
FROM maven:3.9-eclipse-temurin-17 AS builder
WORKDIR /app
# Copy pom.xml first for dependency caching
COPY pom.xml ./
# Download dependencies (cached layer)
RUN mvn dependency:go-offline -B || true
# Copy source code
COPY src ./src
# Build the application
RUN mvn clean package -DskipTests
# Runtime stage
FROM eclipse-temurin:17-jre
WORKDIR /app
# Create a non-root user
RUN groupadd -r spring && useradd -r -g spring spring
# Copy the built JAR from builder stage
COPY --from=builder /app/target/*.jar app.jar
# Change ownership to non-root user
RUN chown spring:spring app.jar
USER spring:spring
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
# Run the application
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]