erp-java/services/purchase-service/Dockerfile

40 lines
824 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.9-eclipse-temurin-17 AS builder
WORKDIR /app
# 复制pom.xml先下载依赖利用缓存
COPY pom.xml .
RUN mvn dependency:go-offline -B
# 复制源代码并构建
COPY src ./src
RUN mvn clean package -DskipTests -B
# 运行阶段
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
# 创建非root用户
RUN addgroup -g 1001 -S appgroup && \
adduser -u 1001 -S appuser -G appgroup
# 从构建阶段复制jar
COPY --from=builder /app/target/*.jar app.jar
# 复制配置文件
COPY src/main/resources/application.yml config/
# 设置权限
RUN chown -R appuser:appgroup /app
USER appuser
EXPOSE 8010
ENV JAVA_OPTS="-Xms512m -Xmx1024m -XX:+UseG1GC"
ENV SPRING_PROFILES_ACTIVE=prod
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar --spring.config.location=file:./config/"]