mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-17 01:14:40 +08:00
Docs: Add Docker one-click deployment support for all languages
Complete Docker deployment solution with beginner-friendly documentation: **New Docker Files:** - `Dockerfile` - Multi-stage Go backend build with health checks - `web/Dockerfile` - Frontend build with Nginx and API proxy - `docker-compose.yml` - Full orchestration with service dependencies - `.dockerignore` & `web/.dockerignore` - Build optimization - `start.sh` - Convenient management script (start/stop/logs/status) **Comprehensive Documentation:** - `DOCKER_DEPLOY.md` (中文) - Complete Chinese deployment guide - `DOCKER_DEPLOY.en.md` (English) - Complete English deployment guide - Prerequisites & Docker installation (macOS/Windows/Linux) - 3-step quick start (config → start → access) - Service management commands - Advanced configuration (ports, resources, env vars) - Data persistence & backups - Comprehensive troubleshooting - Security recommendations - Production deployment (Nginx, HTTPS, Docker Swarm) - Monitoring & logging setup **README Updates (All 4 Languages):** - README.md (English) - README.zh-CN.md (中文) - README.uk.md (Українська) - README.ru.md (Русский) Added prominent "Option A: Docker One-Click Deployment" section at the beginning of Quick Start in all languages. Clearly marked as EASIEST method for beginners. Shows 3 simple steps with command examples and links to detailed DOCKER_DEPLOY docs. **Key Features:** - One-command deployment: `./start.sh start --build` - Auto-handles all dependencies (Go, Node.js, TA-Lib) - Health checks for both services - Data persistence (logs, cache, config) - Log rotation (10MB × 3 files) - Easy service management - Beginner-friendly for complete newcomers **User Benefits:** - No need to install Go, Node.js, or TA-Lib manually - Works on macOS, Windows, Linux - Perfect for non-developers - Production-ready with best practices This makes NOFX truly accessible to beginners as requested: "真就让小白都能一键开始" Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
456
DOCKER_DEPLOY.en.md
Normal file
456
DOCKER_DEPLOY.en.md
Normal file
@@ -0,0 +1,456 @@
|
||||
# 🐳 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)
|
||||
```bash
|
||||
# Install Docker
|
||||
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||
sudo sh get-docker.sh
|
||||
|
||||
# Install Docker Compose
|
||||
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
# Add current user to docker group
|
||||
sudo usermod -aG docker $USER
|
||||
newgrp docker
|
||||
|
||||
# Verify installation
|
||||
docker --version
|
||||
docker-compose --version
|
||||
```
|
||||
|
||||
## 🚀 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
|
||||
```
|
||||
|
||||
**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/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)
|
||||
|
||||
**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
|
||||
|
||||
# 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
|
||||
```
|
||||
|
||||
### 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/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
|
||||
```
|
||||
|
||||
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.
|
||||
Reference in New Issue
Block a user