49 lines
1.1 KiB
Plaintext
49 lines
1.1 KiB
Plaintext
# 网关服务Dockerfile
|
|
FROM openjdk:17-jdk-alpine
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 安装必要的工具
|
|
RUN apk add --no-cache curl tzdata && \
|
|
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
|
echo "Asia/Shanghai" > /etc/timezone
|
|
|
|
# 复制Maven构建文件
|
|
COPY pom.xml ./
|
|
COPY emotion-common ./emotion-common
|
|
COPY emotion-gateway ./emotion-gateway
|
|
|
|
# 安装Maven
|
|
RUN apk add --no-cache maven
|
|
|
|
# 构建应用
|
|
RUN mvn clean package -DskipTests -pl emotion-gateway -am
|
|
|
|
# 创建运行用户
|
|
RUN addgroup -g 1000 emotion && \
|
|
adduser -D -s /bin/sh -u 1000 -G emotion emotion
|
|
|
|
# 复制jar文件
|
|
RUN cp emotion-gateway/target/emotion-gateway-*.jar app.jar
|
|
|
|
# 设置文件权限
|
|
RUN chown -R emotion:emotion /app
|
|
|
|
# 切换到非root用户
|
|
USER emotion
|
|
|
|
# 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD curl -f http://localhost:9000/actuator/health || exit 1
|
|
|
|
# 暴露端口
|
|
EXPOSE 9000
|
|
|
|
# 启动命令
|
|
ENTRYPOINT ["java", "-jar", \
|
|
"-Xms512m", "-Xmx1024m", \
|
|
"-Djava.security.egd=file:/dev/./urandom", \
|
|
"-Dspring.profiles.active=docker", \
|
|
"app.jar"]
|