-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
50 lines (35 loc) · 1.09 KB
/
Dockerfile
File metadata and controls
50 lines (35 loc) · 1.09 KB
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
43
44
45
46
47
48
49
50
# Multi-stage build for Spring Boot application
FROM eclipse-temurin:17-jdk-jammy AS builder
# Set working directory
WORKDIR /app
# Copy Maven wrapper and pom.xml first for better caching
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
# Make mvnw executable
RUN chmod +x mvnw
# Download dependencies (this layer will be cached if pom.xml doesn't change)
RUN ./mvnw dependency:go-offline
# Copy source code
COPY src src
# Build the application
RUN ./mvnw clean package -DskipTests
# Runtime stage
FROM eclipse-temurin:17-jre-jammy
# Create non-root user for security
RUN addgroup --system spring && adduser --system spring --ingroup spring
# Set working directory
WORKDIR /app
# Copy the built JAR from builder stage
COPY --from=builder /app/target/*.jar app.jar
# Change ownership to spring user
RUN chown spring:spring app.jar
# Switch to non-root user
USER spring
# Expose the port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8080/actuator/health || exit 1
# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]