From 2bfbd34bfc8fc6e3fe70b46ab9622aeec89c8a7d Mon Sep 17 00:00:00 2001 From: zzx-coder <2293314358@qq.com> Date: Tue, 12 May 2026 20:59:07 +0800 Subject: [PATCH] optimize: improve Dockerfile with aliyun mirror and best practices - Use aliyun mirror for node:18-alpine base image - Add system dependencies for npm package compilation - Optimize build caching with layered COPY - Fix build command to remove incorrect locale parameter - Add EXPOSE 3000 for container networking - Add environment variables NODE_ENV and PORT - Add healthcheck for container monitoring - Improve workdir naming and structure --- Dockerfile | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 09b6efe..29530bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,39 @@ -FROM node:18-alpine +FROM registry.cn-hangzhou.aliyuncs.com/ruohshi/node:18-alpine LABEL maintainer="yuankaifneg <2894340009@qq.com>" -WORKDIR /gitlink_help_center +# 安装必要的系统依赖 +RUN apk add --no-cache \ + git \ + python3 \ + make \ + g++ \ + bash -COPY ./ /gitlink_help_center/ +# 设置工作目录 +WORKDIR /app -RUN yarn install -RUN npm run build -- --locale zh-cn +# 优先复制package.json和yarn.lock以利用Docker缓存 +COPY package.json yarn.lock ./ + +# 安装依赖 +RUN yarn install --frozen-lockfile + +# 复制项目文件 +COPY . . + +# 构建应用 +RUN npm run build + +# 暴露端口 +EXPOSE 3000 + +# 设置环境变量 +ENV NODE_ENV=production +ENV PORT=3000 + +# 健康检查 +HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ + CMD node -e "require('http').get('http://localhost:3000', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" + +# 启动应用 CMD ["npm", "run", "serve"]