novel-reader/Dockerfile
2025-12-06 18:19:46 +08:00

34 lines
783 B
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 多阶段构建 - 构建阶段
FROM maven:3.8-eclipse-temurin-8 AS builder
WORKDIR /app
# 先复制pom.xml利用Docker缓存下载依赖
COPY pom.xml .
RUN mvn dependency:go-offline -B
# 复制源代码并构建
COPY src ./src
RUN mvn package -DskipTests -B
# 运行阶段 - 使用Eclipse Temurin JRE镜像
FROM eclipse-temurin:8-jre
WORKDIR /app
# 设置时区为中国
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 从构建阶段复制jar包
COPY --from=builder /app/target/*.jar app.jar
# 暴露端口
EXPOSE 8080
# JVM优化参数适合小内存设备如NAS
ENV JAVA_OPTS="-Xms128m -Xmx256m -XX:+UseG1GC -XX:MaxGCPauseMillis=100"
# 启动命令
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]