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
This commit is contained in:
parent
1f90427fb7
commit
4d7b72d9e5
46
Dockerfile.simple
Normal file
46
Dockerfile.simple
Normal file
@ -0,0 +1,46 @@
|
||||
# 简化的单阶段构建
|
||||
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"]
|
Loading…
x
Reference in New Issue
Block a user