File size: 10,098 Bytes
dde4052 | 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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | # 🐳 Docker One-Click Deployment Guide
This guide will help you quickly deploy the NOFX AI Trading Competition System using Docker.
## 📋 Prerequisites
Before you begin, ensure your system has:
- **Docker**: Version 20.10 or higher
- **Docker Compose**: Version 2.0 or higher
### Installing Docker
#### macOS / Windows
Download and install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
#### Linux (Ubuntu/Debian)
> #### Docker Compose Version Notes
>
> **New User Recommendation:**
> - **Use Docker Desktop**: Automatically includes latest Docker Compose, no separate installation needed
> - Simple installation, one-click setup, provides GUI management
> - Supports macOS, Windows, and some Linux distributions
>
> **Upgrading User Note:**
> - **Deprecating standalone docker-compose**: No longer recommended to download the independent Docker Compose binary
> - **Use built-in version**: Docker 20.10+ includes `docker compose` command (with space)
> - If still using old `docker-compose`, please upgrade to new syntax
*Recommended: Use Docker Desktop (if available) or Docker CE with built-in Compose*
```bash
# Install Docker (includes compose)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Add user to docker group
sudo usermod -aG docker $USER
newgrp docker
# Verify installation (new command)
docker --version
docker compose --version # Docker 24+ includes this, no separate installation needed
```
## 🚀 Quick Start (3 Steps)
### Step 1: Prepare Configuration File
```bash
# Copy configuration template
cp config.json.example config.json
# Edit configuration file with your API keys
nano config.json # or use any other editor
⚠️ **Note**: Basic config.json is still needed for some settings, but ~~trader configurations~~ are now done through the web interface.
```
**Required fields:**
```json
{
"traders": [
{
"id": "my_trader",
"name": "My AI Trader",
"ai_model": "deepseek",
"binance_api_key": "YOUR_BINANCE_API_KEY", // ← Your Binance API Key
"binance_secret_key": "YOUR_BINANCE_SECRET_KEY", // ← Your Binance Secret Key
"deepseek_key": "YOUR_DEEPSEEK_API_KEY", // ← Your DeepSeek API Key
"initial_balance": 1000.0,
"scan_interval_minutes": 3
}
],
"use_default_coins": true,
"api_server_port": 8080
}
```
### Step 2: One-Click Start
```bash
# Build and start all services (first run)
docker compose up -d --build
# Subsequent starts (without rebuilding)
docker compose up -d
```
**Startup options:**
- `--build`: Build Docker images (use on first run or after code updates)
- `-d`: Run in detached mode (background)
### Step 3: Access the System
Once deployed, open your browser and visit:
- **Web Interface**: http://localhost:3000
- **API Health Check**: http://localhost:8080/api/health
## 📊 Service Management
### View Running Status
```bash
# View all container status
docker compose ps
# View service health status
docker compose ps --format json | jq
```
### View Logs
```bash
# View all service logs
docker compose logs -f
# View backend logs only
docker compose logs -f backend
# View frontend logs only
docker compose logs -f frontend
# View last 100 lines
docker compose logs --tail=100
```
### Stop Services
```bash
# Stop all services (keep data)
docker compose stop
# Stop and remove containers (keep data)
docker compose down
# Stop and remove containers and volumes (clear all data)
docker compose down -v
```
### Restart Services
```bash
# Restart all services
docker compose restart
# Restart backend only
docker compose restart backend
# Restart frontend only
docker compose restart frontend
```
### Update Services
```bash
# Pull latest code
git pull
# Rebuild and restart
docker compose up -d --build
```
## 🔧 Advanced Configuration
### Change Ports
Edit `docker-compose.yml` to modify port mappings:
```yaml
services:
backend:
ports:
- "8080:8080" # Change to "your_port:8080"
frontend:
ports:
- "3000:80" # Change to "your_port:80"
```
### Resource Limits
Add resource limits in `docker-compose.yml`:
```yaml
services:
backend:
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G
```
### Environment Variables
Create `.env` file to manage environment variables:
```bash
# .env
TZ=Asia/Shanghai
BACKEND_PORT=8080
FRONTEND_PORT=3000
```
Then use in `docker-compose.yml`:
```yaml
services:
backend:
ports:
- "${BACKEND_PORT}:8080"
```
## 📁 Data Persistence
The system automatically persists data to local directories:
- `./decision_logs/`: AI decision logs
- `./coin_pool_cache/`: Coin pool cache
- ~~`./config.json`: Configuration file (mounted)~~ (Deprecated)
**Data locations:**
```bash
# View data directories
ls -la decision_logs/
ls -la coin_pool_cache/
# Backup data
tar -czf backup_$(date +%Y%m%d).tar.gz decision_logs/ coin_pool_cache/ ~~config.json~~ trading.db
# Restore data
tar -xzf backup_20241029.tar.gz
```
## 🐛 Troubleshooting
### Container Won't Start
```bash
# View detailed error messages
docker compose logs backend
docker compose logs frontend
# Check container status
docker compose ps -a
# Rebuild (clear cache)
docker compose build --no-cache
```
### Port Already in Use
```bash
# Find process using the port
lsof -i :8080 # backend port
lsof -i :3000 # frontend port
# Kill the process
kill -9 <PID>
```
### Configuration File Not Found
```bash
# ~~Ensure config.json exists~~
# ~~ls -la config.json~~
# ~~If not exists, copy template~~
# ~~cp config.json.example config.json~~
*Note: Now using SQLite database for configuration storage, no longer need config.json*
```
### Health Check Failing
```bash
# Check health status
docker inspect nofx-backend | jq '.[0].State.Health'
docker inspect nofx-frontend | jq '.[0].State.Health'
# Manually test health endpoints
curl http://localhost:8080/api/health
curl http://localhost:3000/health
```
### Frontend Can't Connect to Backend
```bash
# Check network connectivity
docker compose exec frontend ping backend
# Check if backend service is running
docker compose exec frontend wget -O- http://backend:8080/health
```
### Clean Docker Resources
```bash
# Clean unused images
docker image prune -a
# Clean unused volumes
docker volume prune
# Clean all unused resources (use with caution)
docker system prune -a --volumes
```
## 🔐 Security Recommendations
1. ~~**Don't commit config.json to Git**~~
```bash
# ~~Ensure config.json is in .gitignore~~
# ~~echo "config.json" >> .gitignore~~
```
*Note: Now using trading.db database, ensure not to commit sensitive data*
2. **Use environment variables for sensitive data**
```yaml
# docker-compose.yml
services:
backend:
environment:
- BINANCE_API_KEY=${BINANCE_API_KEY}
- BINANCE_SECRET_KEY=${BINANCE_SECRET_KEY}
```
3. **Restrict API access**
```yaml
# Only allow local access
services:
backend:
ports:
- "127.0.0.1:8080:8080"
```
4. **Regularly update images**
```bash
docker compose pull
docker compose up -d
```
## 🌐 Production Deployment
### Using Nginx Reverse Proxy
```nginx
# /etc/nginx/sites-available/nofx
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /api/ {
proxy_pass http://localhost:8080/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
```
### Configure HTTPS (Let's Encrypt)
```bash
# Install Certbot
sudo apt-get install certbot python3-certbot-nginx
# Get SSL certificate
sudo certbot --nginx -d your-domain.com
# Auto-renewal
sudo certbot renew --dry-run
```
### Using Docker Swarm (Cluster Deployment)
```bash
# Initialize Swarm
docker swarm init
# Deploy stack
docker stack deploy -c docker-compose.yml nofx
# View service status
docker stack services nofx
# Scale services
docker service scale nofx_backend=3
```
## 📈 Monitoring & Logging
### Log Management
```bash
# Configure log rotation (already configured in docker-compose.yml)
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# View log statistics
docker compose logs --timestamps | wc -l
```
### Monitoring Tool Integration
Integrate Prometheus + Grafana for monitoring:
```yaml
# docker-compose.yml (add monitoring services)
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana
ports:
- "3001:3000"
```
## 🆘 Get Help
- **GitHub Issues**: [Submit an issue](https://github.com/yourusername/open-nofx/issues)
- **Documentation**: Check [README.md](README.md)
- **Community**: Join our Discord/Telegram group
## 📝 Command Cheat Sheet
```bash
# Start
docker compose up -d --build # Build and start
docker compose up -d # Start (without rebuilding)
# Stop
docker compose stop # Stop services
docker compose down # Stop and remove containers
docker compose down -v # Stop and remove containers and data
# View
docker compose ps # View status
docker compose logs -f # View logs
docker compose top # View processes
# Restart
docker compose restart # Restart all services
docker compose restart backend # Restart backend
# Update
git pull && docker compose up -d --build
# Clean
docker compose down -v # Clear all data
docker system prune -a # Clean Docker resources
```
---
🎉 Congratulations! You've successfully deployed the NOFX AI Trading Competition System!
If you encounter any issues, please check the [Troubleshooting](#-troubleshooting) section or submit an issue.
|