Files
telegram-management-system/backend-nestjs/Dockerfile
你的用户名 237c7802e5
Some checks failed
Deploy / deploy (push) Has been cancelled
Initial commit: Telegram Management System
Full-stack web application for Telegram management
- Frontend: Vue 3 + Vben Admin
- Backend: NestJS
- Features: User management, group broadcast, statistics

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 15:37:50 +08:00

67 lines
1.3 KiB
Docker
Raw 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.

# 多阶段构建,优化镜像大小
FROM node:18-alpine AS builder
# 设置工作目录
WORKDIR /app
# 复制 package 文件
COPY package*.json ./
# 安装所有依赖(包括 devDependencies
RUN npm ci && npm cache clean --force
# 复制源代码
COPY . .
# 构建应用
RUN npm run build
# 生产阶段
FROM node:18-alpine AS production
# 安装必要的系统工具
RUN apk --no-cache add \
python3 \
py3-pip \
bash \
curl \
dumb-init
# 创建应用用户
RUN addgroup -g 1001 -S nodejs && \
adduser -S nestjs -u 1001
# 设置工作目录
WORKDIR /app
# 复制 package 文件
COPY package*.json ./
# 安装生产依赖
RUN npm ci --only=production && npm cache clean --force
# 从构建阶段复制编译后的代码
COPY --from=builder --chown=nestjs:nodejs /app/dist ./dist
# 复制其他必要文件
COPY --chown=nestjs:nodejs .env.example ./.env
# 创建必要的目录
RUN mkdir -p /app/logs /app/uploads /app/scripts && \
chown -R nestjs:nodejs /app/logs /app/uploads /app/scripts
# 暴露端口
EXPOSE 3000
# 切换到非root用户
USER nestjs
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/health/quick || exit 1
# 使用 dumb-init 作为 PID 1处理信号
ENTRYPOINT ["dumb-init", "--"]
# 启动应用
CMD ["node", "dist/main.js"]