java_demo/Dockerfile.simple
wangtianqi 4d7b72d9e5 feat: Add simplified Dockerfile as backup option
- Add Dockerfile.simple with single-stage build
- Uses system Maven instead of Maven Wrapper
- Simpler and more reliable for environments with wrapper issues
- Can be used as fallback if Buildx build fails
2025-06-24 00:13:20 +08:00

47 lines
1.2 KiB
Docker
Raw Permalink 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 amazoncorretto:17-alpine
# 安装Maven
RUN apk add --no-cache maven
# 设置工作目录
WORKDIR /app
# 复制所有源代码和Maven配置
COPY . .
# 给mvnw脚本添加执行权限如果存在
RUN chmod +x mvnw || true
# 构建应用使用系统Maven避免wrapper问题
RUN mvn clean package -DskipTests -B
# 安装curl用于健康检查
RUN apk add --no-cache curl tzdata
# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 创建非root用户
RUN addgroup -g 1000 spring && adduser -u 1000 -G spring -s /bin/sh -D spring
# 创建应用目录和日志目录
RUN mkdir -p /app/logs && chown -R spring:spring /app
# 切换到非root用户
USER spring
# 暴露端口
EXPOSE 8080
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/api/health || exit 1
# JVM调优参数
ENV JAVA_OPTS="-server -Xms256m -Xmx512m -XX:+UseG1GC -XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
# 启动应用
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar target/*.jar"]