Files
my_bookmate/frontend/Dockerfile
T
gavindiazandClaude Code f63c0c55c9 feat: Docker 化部署(nginx-proxy-manager 反代,单域名 /api 路由)
- docker-compose.yml: backend + frontend 两服务,挂 NPM 所在外部网络、不暴露宿主端口;
  data/uploads 用 bind mount 持久化(deploy/ 下,gitignored)
- backend/Dockerfile: python:3.12-slim + 清华 PyPI 镜像(ARG 可覆盖)
- frontend/Dockerfile: 多阶段 node:22 + npm ci + next build(NEXT_PUBLIC_API_BASE 构建期
  注入,npmmirror 默认)→ next start
- .env.example: 全量部署环境变量模板(compose 替换变量 + 后端密钥)
- deploy/README.md: 服务器部署手册(NPM 配置 / DNS / 数据迁移 / 运维 / 大陆网络)

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-25 15:35:20 +08:00

35 lines
1.1 KiB
Docker

# BookMate 前端镜像:Next.js(经典 next start 方案,最稳妥)
# 构建上下文是仓库根目录,COPY 路径相对仓库根。
# —— 构建阶段:安装依赖 + 生产构建(NEXT_PUBLIC_API_BASE 在此时内联进浏览器代码)——
FROM node:22-alpine AS builder
WORKDIR /app
# 大陆网络默认走 npmmirror 镜像;可在构建时用 --build-arg 覆盖:
# docker compose build --build-arg NPM_REGISTRY=https://registry.npmjs.org frontend
ARG NPM_REGISTRY=https://registry.npmmirror.com
ENV npm_config_registry="$NPM_REGISTRY"
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/ .
ARG NEXT_PUBLIC_API_BASE
ENV NEXT_PUBLIC_API_BASE=$NEXT_PUBLIC_API_BASE
RUN npm run build
# —— 运行阶段:最小化拷贝出 .next / node_modules / public ——
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/package.json /app/package-lock.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.ts ./
EXPOSE 3000
CMD ["npm", "run", "start"]