Files
2026-06-18 09:48:05 +08:00

26 lines
793 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.
# PCM 后端生产镜像(多阶段构建)
# 1) build:安装全部依赖并编译 TypeScript → dist
# 2) runtime:仅保留生产依赖与 dist,非 root 运行
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# 仅保留生产依赖,缩小运行镜像
RUN npm prune --omit=dev
FROM node:20-alpine AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
# 拷贝生产依赖与编译产物(归属 node 用户)
COPY --from=build --chown=node:node /app/node_modules ./node_modules
COPY --from=build --chown=node:node /app/dist ./dist
COPY --from=build --chown=node:node /app/package.json ./package.json
EXPOSE 3000
USER node
# busybox wget 做容器健康检查(见 docker-compose.yml
CMD ["node", "dist/main.js"]