Files
crewai/DOCKER.md
2026-03-13 21:09:44 +08:00

148 lines
2.5 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.

# Docker 部署指南
## 快速启动
### 方式一:使用 Docker Compose (推荐)
1. **配置环境变量**
```bash
# 复制环境变量文件
cp .env.example .env
# 编辑 .env 文件,填入你的 DashScope API Key
DASHSCOPE_API_KEY=your_api_key_here
```
2. **启动服务**
```bash
docker-compose up -d
```
3. **查看日志**
```bash
docker-compose logs -f
```
4. **访问应用**
- API 文档http://localhost:8080/docs
- 前端界面http://localhost:8080/static/index.html
5. **停止服务**
```bash
docker-compose down
```
### 方式二:使用 Docker 构建
1. **构建镜像**
```bash
docker build -t sdlc-agent-demo:latest .
```
2. **运行容器**
```bash
docker run -d \
-p 8080:8080 \
-e DASHSCOPE_API_KEY=your_api_key_here \
-v $(pwd)/logs:/app/logs \
--name sdlc-agent \
sdlc-agent-demo:latest
```
3. **查看日志**
```bash
docker logs -f sdlc-agent
```
4. **停止并删除容器**
```bash
docker stop sdlc-agent && docker rm sdlc-agent
```
## 环境变量
| 变量名 | 说明 | 默认值 | 必需 |
|--------|------|--------|------|
| `DASHSCOPE_API_KEY` | 阿里云 DashScope API Key | 无 | ✅ |
| `PYTHONUNBUFFERED` | Python 输出缓冲设置 | 1 | ❌ |
## 端口说明
| 端口 | 说明 |
|------|------|
| 8080 | HTTP 服务端口 |
## 数据卷
| 路径 | 说明 |
|------|------|
| `./logs` | 日志文件存储目录 |
## 常见问题
### 1. 构建失败
如果遇到依赖安装失败,尝试使用国内镜像:
```dockerfile
# 在 Dockerfile 开头添加
FROM registry.cn-hangzhou.aliyuncs.com/library/python:3.11-slim
```
### 2. API Key 配置
确保在 `.env` 文件中正确配置了 DashScope API Key:
```bash
DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx
```
### 3. 网络问题
如果容器无法访问外网,检查 Docker 网络配置:
```bash
docker network inspect sdlc-network
```
## 生产环境建议
1. **使用 secrets 管理敏感信息**
```yaml
secrets:
dashscope_api_key:
external: true
services:
sdlc-agent:
secrets:
- dashscope_api_key
```
2. **添加资源限制**
```yaml
deploy:
resources:
limits:
cpus: '2'
memory: 2G
```
3. **配置日志轮转**
```yaml
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
```
4. **使用持久化存储**
```yaml
volumes:
- sdlc-data:/app/logs
volumes:
sdlc-data:
```