-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
54 lines (42 loc) · 1.34 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
# Step 1: 构建自定义 JRE
FROM eclipse-temurin:17-jdk-alpine AS jre-builder
WORKDIR /build
# Copy the project source code
COPY . ./
# Build the package
RUN ./mvnw -DoutputFile=target/mvn-dependency-list.log -B -DskipTests clean dependency:list install
# Install the necessary packages
RUN apk update && apk add binutils
# Build the JRE
RUN ${JAVA_HOME}/bin/jlink \
--verbose \
--add-modules ALL-MODULE-PATH \
--no-header-files \
--no-man-pages \
--compress=2 \
--strip-debug \
--output /optimized-jdk-17
# Stage 2: Create a minimal image
FROM alpine:latest
ENV JAVA_HOME=/opt/jdk/jre-17
ENV PATH=$PATH:$JAVA_HOME/bin
COPY --from=jre-builder /build/application/target/*.jar /app/app.jar
COPY --from=jre-builder /optimized-jdk-17 $JAVA_HOME
# Declare environment variable with default value
ENV SPRING_PROFILES_ACTIVE=prod
# Set the working directory in the container
WORKDIR /app
EXPOSE 8080
ENV JAVA_OPTS="\
-XX:+UseContainerSupport \
-XX:MaxRAMPercentage=75.0 \
-XX:InitialRAMPercentage=75.0 \
-Xss512k \
-XX:MetaspaceSize=64m \
-XX:+UseG1GC \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=/dumps/heap-dump.hprof"
# Run the app by dynamically finding the JAR file in the target directory
CMD ["sh", "-c", "java $JAVA_OPTS -jar \
-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE} \
app.jar"]