feat: 添加 Docker 部署配置

- 添加 Dockerfile (多阶段构建: Node 构建 → Nginx 托管)
- 添加 docker-compose.yml (端口 8801, 自动重启)
- 添加 .dockerignore (减少构建体积)
- 添加 docker-deploy.md (部署文档)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jowe
2026-03-24 01:18:52 +08:00
parent 9dfa2a9532
commit 7fe1586dc0
4 changed files with 159 additions and 0 deletions

43
.dockerignore Normal file
View File

@@ -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

33
Dockerfile Normal file
View File

@@ -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;"]

23
docker-compose.yml Normal file
View File

@@ -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

60
docker-deploy.md Normal file
View File

@@ -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