diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ee3f9af --- /dev/null +++ b/.dockerignore @@ -0,0 +1,43 @@ +# Node.js +node_modules +npm-debug.log +yarn-error.log + +# Build outputs +dist +build + +# Git +.git +.gitignore +.gitattributes + +# IDE +.vscode +.idea +*.swp +*.swo + +# Documentation +README.md +PRD.md +*.md +!docker-deploy.md + +# Docker +Dockerfile +docker-compose.yml +.dockerignore + +# Environment +.env +.env.local +.env.*.local + +# Test +coverage +.nyc_output + +# Misc +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f2682dc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM node:20-alpine AS builder + +WORKDIR /app + +# 安装 pnpm(如果需要) +# RUN corepack enable && corepack prepare pnpm@latest --activate + +# 复制依赖文件 +COPY package*.json ./ + +# 安装依赖 +RUN npm install + +# 复制源码 +COPY . . + +# 构建生产版本 +RUN npm run build + +# 运行阶段 - 使用 Nginx +FROM nginx:alpine + +# 从构建阶段复制产物 +COPY --from=builder /app/dist /usr/share/nginx/html + +# 复制 Nginx 配置(可选) +# COPY nginx.conf /etc/nginx/conf.d/default.conf + +# 暴露端口 +EXPOSE 80 + +# 启动 Nginx +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..86cf32d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3.8' + +services: + web: + build: + context: . + dockerfile: Dockerfile + container_name: tianxuan-company + ports: + - "8801:80" + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "-q", "--spider", "http://localhost/"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 10s + networks: + - tianxuan-network + +networks: + tianxuan-network: + driver: bridge \ No newline at end of file diff --git a/docker-deploy.md b/docker-deploy.md new file mode 100644 index 0000000..8f6c7e4 --- /dev/null +++ b/docker-deploy.md @@ -0,0 +1,60 @@ +# 天选公司 - Docker 部署配置 + +## 快速部署 + +### 首次部署 +```bash +# 1. 拉取代码 +git pull + +# 2. 构建并启动容器 +docker-compose up -d --build + +# 3. 查看日志 +docker-compose logs -f +``` + +### 更新部署 +```bash +# 1. 拉取最新代码 +git pull + +# 2. 重新构建并重启 +docker-compose up -d --build +``` + +### 常用命令 +```bash +# 启动 +docker-compose up -d + +# 停止 +docker-compose down + +# 重启 +docker-compose restart + +# 查看状态 +docker-compose ps + +# 查看日志 +docker-compose logs -f + +# 查看实时资源 +docker stats +``` + +## 端口配置 + +- 容器内:80 (Nginx) +- 宿主机映射:8801 + +## 1Panel 反向代理配置 + +目标地址:`http://127.0.0.1:8801` + +## 环境说明 + +- Node 版本:20-alpine (构建阶段) +- Nginx 版本:alpine (运行阶段) +- 构建产物直接打包进容器,无需在宿主机安装 Node.js \ No newline at end of file