-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.without-package
More file actions
46 lines (37 loc) · 1.13 KB
/
Copy pathDockerfile.without-package
File metadata and controls
46 lines (37 loc) · 1.13 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
# Step 1: 构建自定义 JRE
FROM eclipse-temurin:17-jdk-alpine AS jre-builder
# 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 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=dev
# 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"]