Files
wwjcloud/docker/Dockerfile

45 lines
1015 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.
# ========================================
# NestJS Backend Dockerfile
# ========================================
FROM node:20-alpine AS builder
WORKDIR /app
# 复制package文件
COPY package*.json ./
# 安装所有依赖(包括 devDependencies用于构建
RUN npm ci && npm cache clean --force
# 复制源码
COPY . .
# 构建应用
RUN npm run build
# 删除 devDependencies只保留生产依赖
RUN npm prune --production
# ========================================
# Production Stage
# ========================================
FROM node:20-alpine
WORKDIR /app
# 复制依赖和构建产物
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package*.json ./
# 暴露端口
EXPOSE 3000
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s \
CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# 启动应用
CMD ["node", "dist/main"]