Files
smart-admin/Dockerfile
2025-12-13 23:00:09 +08:00

47 lines
1.3 KiB
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.

# 使用Eclipse Temurin OpenJDK 17作为基础镜像离线部署
FROM eclipse-temurin:17-jre-alpine
# 设置工作目录
WORKDIR /app
# 设置时区为东八区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 安装curl用于健康检查和7-zip用于文件解压可选
RUN apk add --no-cache curl p7zip
# 设置构建参数
ARG VERSION=1.0.0
ARG BUILD_TIME=unknown
ENV APP_VERSION=${VERSION}
ENV BUILD_TIME=${BUILD_TIME}
# 复制Maven构建的JAR文件
COPY target/*.jar app.jar
# 创建非root用户 (Alpine Linux)
RUN addgroup -g 1001 -S appuser && adduser -S -D -H -u 1001 -s /sbin/nologin -G appuser -g appuser appuser
# 创建必要的目录
RUN mkdir -p /app/uploads /app/extracts /app/logs /app/config
# 设置目录权限
RUN chown -R appuser:appuser /app
# 切换到非root用户
USER appuser
# 暴露端口
EXPOSE 8080
# 设置JVM参数
ENV JAVA_OPTS="-Xmx1g -Xms512m -XX:+UseG1GC -XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# 启动应用
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]