-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (33 loc) · 1.14 KB
/
Dockerfile
File metadata and controls
47 lines (33 loc) · 1.14 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
# Multi-stage build for Spring Boot application
# Stage 1: Build the application
FROM maven:3.9.9-eclipse-temurin-17 AS build
# Set working directory
WORKDIR /app
# Copy pom.xml and download dependencies (for better layer caching)
COPY pom.xml .
RUN mvn dependency:go-offline -B
# Copy source code
COPY src ./src
# Build the application (skip tests for faster builds)
RUN mvn clean package -DskipTests
# Stage 2: Create the runtime image
FROM eclipse-temurin:17-jre-jammy
# Set working directory
WORKDIR /app
# Create a non-root user for security
RUN groupadd -r spring && useradd -r -g spring spring
# Copy the built jar from the build stage
COPY --from=build /app/target/*.jar app.jar
# Change ownership to non-root user
RUN chown -R spring:spring /app
# Switch to non-root user
USER spring
# Expose the application port
EXPOSE 8080
# Set JVM options for better performance in containers
ENV JAVA_OPTS="-Xmx512m -Xms256m"
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/actuator/health || exit 1
# Run the application
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]