update:'修改dockerfile'

main
ngks 1 month ago
parent f4dabf563b
commit 679cf6addc

@ -1,31 +1,21 @@
# 构建阶段 # 使用轻量级的 Nginx 镜像
FROM node:20-alpine AS builder FROM nginx:alpine
WORKDIR /app
# 复制依赖清单
COPY package.json pnpm-lock.yaml ./
# 设置 npm 和 pnpm 使用国内镜像源(关键!)
RUN npm config set registry https://registry.npmmirror.com && \
npm install -g pnpm && \
pnpm config set registry https://registry.npmmirror.com
# 安装依赖(现在会走淘宝镜像)
RUN pnpm install --frozen-lockfile
# 复制源码并构建 # 复制自定义 Nginx 配置(如果有)
COPY . . RUN rm -f /etc/nginx/conf.d/default.conf
RUN pnpm run build:prod # 生成 dist-prod 目录 COPY nginx.conf /etc/nginx/conf.d/default.conf
# 运行阶段 # 将本地 dist 目录复制到容器中
FROM nginx:alpine COPY dist /usr/share/nginx/html
# 复制前端产物 # 暴露 8088 端口
COPY --from=builder /app/dist-prod /usr/share/nginx/html EXPOSE 8088
# 复制 Nginx 配置 # 创建启动脚本
COPY nginx.conf /etc/nginx/nginx.conf RUN echo -e '#!/bin/sh\n\
echo "Waiting for MySQL/Redis/MinIO to start..."\n\
sleep 15\n\
nginx -g "daemon off;"' > /start.sh && \
chmod +x /start.sh
EXPOSE 80 CMD ["/start.sh"]
CMD ["nginx", "-g", "daemon off;"]
Loading…
Cancel
Save