chore(docker): move Dockerfile and docker-compose.yml from wwjcloud-nest to root docker/
This commit is contained in:
44
docker/Dockerfile
Normal file
44
docker/Dockerfile
Normal file
@@ -0,0 +1,44 @@
|
||||
# ========================================
|
||||
# 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"]
|
||||
|
||||
Reference in New Issue
Block a user