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