You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
buffer_platform/DOCKER_DEPLOY.md

284 lines
5.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 期货智析缓冲平台 - Docker部署文档
## 目录结构
```
buffer_platform/
├── app/ # 应用代码
├── static/ # 前端静态文件
├── data/ # 本地数据目录(开发用)
├── Dockerfile # Docker镜像构建文件
├── docker-compose.yml # Docker Compose配置文件
├── .env # 环境变量配置
├── .dockerignore # Docker构建忽略文件
├── requirements.txt # Python依赖
├── deploy.bat # 一键部署脚本
├── start.bat # 启动服务
├── stop.bat # 停止服务
├── logs.bat # 查看日志
└── backup.bat # 数据库备份
```
## 环境要求
- Docker Desktop for Windows
- Docker Compose v3.8+
- Windows 10/11
## 快速部署
### 方式一:一键部署(推荐)
```powershell
cd e:\docker_workspace\cobot2.0_WorkHorse\app\working\workspaces\default\share_data\project\market_data_colector_platform\buffer_platform
deploy.bat
```
### 方式二:手动部署
```powershell
# 1. 创建数据目录
mkdir E:\docker_workspace\futures_datas
mkdir E:\docker_workspace\futures_datas\logs
# 2. 构建并启动
docker-compose up -d --build
# 3. 查看状态
docker-compose ps
```
## 访问地址
| 页面 | 地址 |
|------|------|
| **品种分析** | http://localhost:9600/futures-analysis |
| **配置管理** | http://localhost:9600/ui |
| **AI配置** | http://localhost:9600/ai-config |
| **API文档** | http://localhost:9600/docs |
| **健康检查** | http://localhost:9600/api/v1/health |
## 数据持久化
### 挂载路径
| 宿主机路径 | 容器路径 | 说明 |
|-----------|----------|------|
| `E:\docker_workspace\futures_datas` | `/app/data` | SQLite数据库及缓存数据 |
| `E:\docker_workspace\futures_datas\logs` | `/app/logs` | 日志文件 |
### 数据目录结构
容器启动后,`E:\docker_workspace\futures_datas` 目录将包含:
```
E:\docker_workspace\futures_datas\
├── buffer.db # SQLite数据库文件
├── futures_analysis.db # AI分析数据库
└── logs/ # 日志目录
└── (应用日志文件)
```
## 常用管理命令
### 使用批处理脚本
```powershell
deploy.bat # 一键部署
start.bat # 启动服务
stop.bat # 停止服务
logs.bat # 查看日志
backup.bat # 数据库备份
```
### 使用Docker Compose命令
```powershell
# 启动服务
docker-compose start
# 停止服务
docker-compose stop
# 重启服务
docker-compose restart
# 查看状态
docker-compose ps
# 查看日志
docker-compose logs -f
# 停止并删除容器
docker-compose down
# 重新构建并启动
docker-compose up -d --build
```
## 环境变量配置
可在 `.env` 文件或 `docker-compose.yml` 中修改:
| 变量名 | 默认值 | 说明 |
|--------|--------|------|
| `BUFFER_DB_PATH` | `/app/data/buffer.db` | 数据库文件路径 |
| `BUFFER_HOST` | `0.0.0.0` | 服务监听地址 |
| `BUFFER_PORT` | `8600` | 容器内端口 |
| `CACHE_TTL` | `300` | 缓存过期时间(秒) |
| `BUFFER_LOG_LEVEL` | `INFO` | 日志级别 |
| `MAX_WORKERS` | `2` | 并发采集数 |
## 端口修改
如需修改宿主机绑定端口,编辑 `docker-compose.yml`
```yaml
ports:
- "9600:8600" # 将9600改为其他端口
```
## 数据备份与恢复
### 方式一:使用备份脚本
```powershell
backup.bat
```
### 方式二:手动备份
```powershell
# 停止服务
docker-compose stop
# 复制数据库
xcopy E:\docker_workspace\futures_datas\buffer.db E:\backup\buffer_%date:~0,4%%date:~5,2%%date:~8,2%.db
# 启动服务
docker-compose start
```
### 恢复数据库
```powershell
# 停止服务
docker-compose stop
# 恢复数据库
copy E:\backup\buffer_20260523.db E:\docker_workspace\futures_datas\buffer.db
# 启动服务
docker-compose start
```
## 故障排查
### 容器无法启动
```powershell
# 查看详细日志
docker-compose logs
# 检查容器状态
docker ps -a
# 删除容器重新构建
docker-compose down
docker-compose up -d --build
```
### 端口冲突
```powershell
# 检查端口占用
netstat -ano | findstr "9600"
# 修改docker-compose.yml中的端口映射
```
### 数据库权限问题
确保数据目录存在:
```powershell
mkdir E:\docker_workspace\futures_datas
mkdir E:\docker_workspace\futures_datas\logs
```
### 进入容器
```powershell
docker exec -it futures-buffer-platform /bin/bash
```
### 查看资源使用
```powershell
docker stats futures-buffer-platform
```
## 健康检查
```powershell
# PowerShell
Invoke-WebRequest -Uri http://localhost:9600/api/v1/health
# 浏览器访问
http://localhost:9600/api/v1/health
```
正常响应:
```json
{
"status": "ok",
"service": "market-data-buffer"
}
```
## 更新应用
```powershell
# 1. 备份数据库
backup.bat
# 2. 停止服务
docker-compose stop
# 3. 删除旧容器
docker-compose rm -f
# 4. 重新构建
docker-compose build --no-cache
# 5. 启动新容器
docker-compose up -d
# 6. 验证服务
curl http://localhost:9600/api/v1/health
```
## 安全建议
1. **定期备份数据库** - 使用 `backup.bat` 定期备份
2. **监控日志** - 使用 `logs.bat` 查看异常
3. **限制端口访问** - 防火墙只开放必要端口
4. **数据目录权限** - 确保数据目录有适当权限
## 技术支持
遇到问题请查看日志:
```powershell
logs.bat
```
或进入容器检查:
```powershell
docker exec -it futures-buffer-platform /bin/bash
cd /app/logs
ls -la
```