xiaoai/php_pc/Dockerfile

55 lines
1.4 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ────────────────────
# 第一步:构建阶段
# ────────────────────
FROM node:20 AS builder
WORKDIR /app
# 只拷贝 Yarn 所需的锁文件,避免与 npm 锁文件冲突
COPY package.json yarn.lock ./
# 拷贝环境变量
COPY .env ./
# 提升网络超时,防止安装过程因网络问题失败
RUN yarn config set network-timeout 600000
# 安装依赖,跳过可选依赖(如 fsevents
RUN yarn install --frozen-lockfile
# 拷贝全部源码并构建
COPY . .
RUN yarn build
# ────────────────────
# 第二步:运行阶段(调试用)
# ────────────────────
FROM node:20-slim AS runtime
WORKDIR /app
# 拷贝构建产物和依赖
COPY --from=builder /app/.output .output
COPY --from=builder /app/node_modules ./node_modules
# 拷贝源代码以便调试
COPY --from=builder /app/src ./src
COPY --from=builder /app/nuxt.config.ts ./nuxt.config.ts
COPY --from=builder /app/package.json ./package.json
# 安装调试工具和 serve
RUN apt-get update \
&& apt-get install -y nano net-tools bash \
&& npm install -g serve \
&& rm -rf /var/lib/apt/lists/*
# 暴露端口
EXPOSE 8091
# 配置环境变量,让 Nitro 监听在 0.0.0.0:8091
ENV HOST=0.0.0.0
ENV PORT=8091
# 默认启动进入交互式 shell以便调试完成后可改为直接启动服务
CMD ["bash"]