Files
codexautopool/DOCKER.md

163 lines
3.6 KiB
Markdown
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.
# Codex Pool Docker 部署指南
## 架构
前后端一体化部署Go 后端嵌入前端静态文件,单一容器运行。
```
┌─────────────────────────────────────────┐
│ Codex Pool │
│ ┌─────────────────────────────────┐ │
│ │ Frontend (嵌入) │ │
│ │ - React SPA │ │
│ └─────────────────────────────────┘ │
│ ┌─────────────────────────────────┐ │
│ │ Backend (Go) │ │
│ │ - API 服务 │ │
│ │ - Chromium 浏览器自动化 │ │
│ │ - SQLite 数据库 │ │
│ └─────────────────────────────────┘ │
│ :8848 │
└─────────────────────────────────────────┘
```
## 快速开始
### 1. 创建数据目录
```bash
mkdir -p data
```
### 2. 构建并启动
```bash
# 构建镜像并启动
docker-compose up -d --build
# 查看日志
docker-compose logs -f
```
### 3. 配置 (通过 Web 界面)
首次启动后,访问 Web 界面进行配置:
1. 打开 http://localhost:8848
2. 进入 **系统配置**
3. 配置 S2A API 地址和 Admin Key
4. 配置邮箱服务
5. 根据需要启用代理
**配置自动保存到数据库,无需重启服务。**
## 常用命令
```bash
# 停止服务
docker-compose down
# 重启服务
docker-compose restart
# 查看状态
docker-compose ps
# 重新构建并启动
docker-compose up -d --build
# 进入容器
docker-compose exec codex-pool sh
```
## 配置说明
### 环境变量
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `PORT` | 8848 | 服务端口 |
| `BIND_HOST` | 0.0.0.0 | 绑定地址 |
| `TZ` | Asia/Shanghai | 时区 |
### 数据持久化
| 路径 | 说明 |
|------|------|
| `./data/codex-pool.db` | SQLite 数据库 (包含配置) |
### 代理配置
在 Web 界面中配置代理:
- 进入 系统配置 → 核心配置
- 开启 **代理设置** 开关
- 填入代理地址,如 `http://host.docker.internal:7890`
## 生产环境建议
### 1. 使用反向代理
使用 Nginx/Caddy/Traefik 提供 HTTPS
```nginx
server {
listen 443 ssl;
server_name codex-pool.example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://127.0.0.1:8848;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
```
### 2. 资源限制
```yaml
services:
codex-pool:
deploy:
resources:
limits:
cpus: '2'
memory: 2G
```
### 3. 日志管理
```yaml
services:
codex-pool:
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
```
## 故障排查
### 浏览器自动化失败
检查 Chromium 是否正常:
```bash
docker-compose exec codex-pool chromium-browser --version
```
### 无法连接代理
确保代理配置正确并已启用:
```bash
docker-compose exec codex-pool curl -v --proxy http://host.docker.internal:7890 https://www.google.com
```
### 数据库检查
```bash
docker-compose exec codex-pool ls -la /app/data/
```