Commit 0c0f5986 authored by xiezhi's avatar xiezhi

简化优化Dockerfile

- 移除不必要的用户创建和权限设置
- 简化环境变量配置
- 移除复杂的entrypoint脚本
- 优化依赖安装流程
- 调整健康检查超时时间
- 使用固定端口8000提高稳定性
parent 32ba80f2
......@@ -6,35 +6,20 @@ WORKDIR /app
# 设置环境变量
ENV NODE_ENV=production
ENV PORT=${APP_PORT_1:-8000}
# 复制package文件
# 复制package文件并安装依赖
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force
# 复制应用文件
COPY . .
# 创建非root用户
RUN addgroup -g 1001 -S nodejs && \
adduser -S kaboom -u 1001
# 更改文件所有权
RUN chown -R kaboom:nodejs /app
USER kaboom
# 暴露端口
EXPOSE ${APP_PORT_1:-8000}
EXPOSE 8000
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${APP_PORT_1:-8000}/ || exit 1
# 复制并设置启动脚本
COPY docker-entrypoint.sh /usr/local/bin/
USER root
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
USER kaboom
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/ || exit 1
# 启动应用
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["npm", "start"]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment