Files
note-book/backend/Dockerfile

40 lines
986 B
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.
# Stage 1: 依赖安装 + 构建
FROM node:24-alpine
WORKDIR /app
# 允许所有包的 postinstall 脚本Prisma/esbuild 需要)
ENV NPM_CONFIG_IGNORE_SCRIPTS=false
# 复制依赖文件
COPY package.json pnpm-lock.yaml ./
COPY .npmrc ./
# 安装依赖pnpm 会读取 .npmrc 中的 onlyBuiltDependencies
RUN corepack enable && pnpm install --frozen-lockfile --config.onlyBuiltDependencies="@prisma/client,@prisma/engines,esbuild,prisma"
# 复制 Prisma schema 并生成客户端
COPY prisma/ ./prisma/
RUN npx prisma generate
# 复制源码并构建
COPY . .
RUN npm run build
# Stage 2: 最小运行时镜像
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# 复制 standalone 输出和静态资源
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
COPY --from=builder /app/prisma ./prisma
EXPOSE 3000
CMD ["node", "server.js"]