File size: 4,959 Bytes
59ce7b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# Docker Deployment
> **Last Updated**: 2025-12-06
This guide covers deploying DeepBoner using Docker.
## Quick Start
```bash
# Build the image
docker build -t deepboner .
# Run the container
docker run -p 7860:7860 deepboner
```
Open http://localhost:7860
## Dockerfile Overview
The project uses a multi-stage approach:
```dockerfile
FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y git curl
# Install uv package manager
RUN pip install uv==0.5.4
# Copy project files
COPY pyproject.toml uv.lock src/ README.md .
# Install runtime dependencies (no dev tools)
RUN uv sync --frozen --no-dev --extra embeddings --extra magentic
# Create non-root user
RUN useradd --create-home appuser
USER appuser
# Pre-download embedding model
RUN uv run python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
# Expose port and run
EXPOSE 7860
CMD ["uv", "run", "python", "-m", "src.app"]
```
## Building
### Basic Build
```bash
docker build -t deepboner .
```
### With Build Arguments
```bash
# Custom tag
docker build -t deepboner:v0.1.0 .
# No cache (clean build)
docker build --no-cache -t deepboner .
```
### Multi-Platform Build
```bash
docker buildx build --platform linux/amd64,linux/arm64 -t deepboner .
```
## Running
### Basic Run
```bash
docker run -p 7860:7860 deepboner
```
### With Environment Variables
```bash
docker run -p 7860:7860 \
-e OPENAI_API_KEY=sk-your-key \
-e NCBI_API_KEY=your-ncbi-key \
-e LOG_LEVEL=INFO \
deepboner
```
### Using .env File
```bash
docker run -p 7860:7860 --env-file .env deepboner
```
### With Persistent Storage
```bash
# Persist ChromaDB data
docker run -p 7860:7860 \
-v $(pwd)/data/chroma:/app/chroma_db \
deepboner
```
### Detached Mode
```bash
docker run -d -p 7860:7860 --name deepboner-app deepboner
```
## Configuration
### Environment Variables
| Variable | Description | Required |
|----------|-------------|----------|
| `OPENAI_API_KEY` | OpenAI API key (premium mode) | No |
| `NCBI_API_KEY` | NCBI API key (higher rate limits) | No |
| `HF_TOKEN` | HuggingFace token | No |
| `LOG_LEVEL` | Logging level (DEBUG, INFO, WARNING, ERROR) | No |
| `MAX_ITERATIONS` | Max search iterations (1-50) | No |
### Ports
| Port | Service |
|------|---------|
| 7860 | Gradio UI + MCP Server |
### Volumes
| Path | Purpose |
|------|---------|
| `/app/chroma_db` | ChromaDB vector store |
| `/app/.cache` | HuggingFace model cache |
## Health Check
The container includes a health check:
```dockerfile
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
```
Check health status:
```bash
docker inspect --format='{{.State.Health.Status}}' deepboner-app
```
## Docker Compose
Create `docker-compose.yml`:
```yaml
version: '3.8'
services:
deepboner:
build: .
ports:
- "7860:7860"
environment:
- LOG_LEVEL=INFO
env_file:
- .env
volumes:
- chroma_data:/app/chroma_db
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:7860/"]
interval: 30s
timeout: 10s
retries: 3
volumes:
chroma_data:
```
Run with:
```bash
docker-compose up -d
```
## Production Considerations
### Resource Limits
```bash
docker run -p 7860:7860 \
--memory=4g \
--cpus=2 \
deepboner
```
### Logging
```bash
# View logs
docker logs deepboner-app
# Follow logs
docker logs -f deepboner-app
# With timestamps
docker logs -t deepboner-app
```
### Security
The container runs as non-root user (`appuser`):
```dockerfile
RUN useradd --create-home appuser
USER appuser
```
Do not:
- Expose ports beyond 7860
- Mount sensitive host paths
- Run as root in production
### Reverse Proxy
For production, use a reverse proxy (nginx, traefik):
```nginx
server {
listen 80;
server_name deepboner.example.com;
location / {
proxy_pass http://localhost:7860;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
```
## Troubleshooting
### Container exits immediately
Check logs:
```bash
docker logs deepboner-app
```
Common causes:
- Missing environment variables
- Port conflict
- Insufficient memory
### Slow startup
First run downloads models. Pre-warm the cache:
```bash
# Build includes model download
docker build -t deepboner .
```
### Out of memory
Increase memory limit:
```bash
docker run -p 7860:7860 --memory=8g deepboner
```
### Cannot connect to port
Check if port is in use:
```bash
lsof -i :7860
```
Use a different port:
```bash
docker run -p 8080:7860 deepboner
```
## Related Documentation
- [HuggingFace Spaces Deployment](huggingface-spaces.md)
- [MCP Integration](mcp-integration.md)
- [Configuration Reference](../reference/configuration.md)
|