This commit is contained in:
hailin 2025-07-28 23:15:12 +08:00
parent 6b9999410b
commit baaf71a864
1 changed files with 16 additions and 11 deletions

View File

@ -5,40 +5,45 @@ FROM node:20 AS builder
WORKDIR /app WORKDIR /app
# 安装依赖
COPY package*.json yarn.lock ./ COPY package*.json yarn.lock ./
COPY .env . COPY .env .
RUN yarn install --frozen-lockfile RUN yarn install --frozen-lockfile
# 拷贝源码并构建
COPY . . COPY . .
COPY . src/ COPY . src/
RUN yarn build RUN yarn build
# ──────────────────── # ────────────────────
# 第二步:运行阶段 # 第二步:运行阶段(调试用)
# ──────────────────── # ────────────────────
FROM node:20-slim AS runtime FROM node:20-slim AS runtime
WORKDIR /app WORKDIR /app
# 拷贝构建产物 # 拷贝构建产物和依赖
COPY --from=builder /app/.output .output COPY --from=builder /app/.output .output
COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/node_modules ./node_modules
# 只拷贝必要的运行文件(不执行 yarn install # 拷贝源代码以便调试
# 如果 Nuxt 构建产物已完整,可不再安装依赖 COPY --from=builder /app/src ./src
# COPY package*.json yarn.lock ./ COPY --from=builder /app/nuxt.config.ts ./nuxt.config.ts
# RUN yarn install --production --frozen-lockfile COPY --from=builder /app/package.json ./package.json
# ✅ 安装 serve 用于启动 SSR 服务 # 安装调试工具和 serve
RUN npm install -g serve RUN apt-get update \
&& apt-get install -y vim net-tools bash \
&& npm install -g serve \
&& rm -rf /var/lib/apt/lists/*
# 暴露端口 # 暴露端口
EXPOSE 8091 EXPOSE 8091
# tell Nitro to listen on 0.0.0.0:8091 # 配置环境
ENV HOST=0.0.0.0 ENV HOST=0.0.0.0
ENV PORT=8091 ENV PORT=8091
# 启动 Nuxt SSR 服务 # 进入交互式 shell 以便调试
CMD ["bash"] CMD ["bash"]
# CMD ["node", ".output/server/index.mjs"]