# XAUBot AI - Docker Integration Summary ## βœ… Completed Tasks ### 1. **Created Dockerfile for Next.js Dashboard** - Multi-stage build for optimization - Standalone output for minimal image size - Production-ready configuration - Non-root user for security **Location:** `web-dashboard/Dockerfile` ### 2. **Created Dockerfile for Python Trading API** - Python 3.11-slim base image - FastAPI server with health checks - Proper dependency management - Volume mounts for data/logs/models **Location:** `Dockerfile` (root directory) ### 3. **Updated Docker Compose Configuration** - 4 services: postgres, trading-api, dashboard, pgadmin - Proper service dependencies and health checks - Custom bridge network for inter-service communication - Environment variable support via .env file - Volume persistence for database and pgadmin **Location:** `docker-compose.yml` ### 4. **Created Environment Configuration** - Template with all required variables - Clear documentation for each setting - Default values for non-sensitive configs **Location:** `docker/.env.docker.example` ### 5. **Created Docker Ignore Files** - Excludes unnecessary files from images - Reduces build context size - Improves build performance **Locations:** - `web-dashboard/.dockerignore` - `.dockerignore` (root) ### 6. **Created Helper Scripts** #### Windows Batch Scripts: - `docker\scripts\docker-start.bat` - Start all services - `docker\scripts\docker-stop.bat` - Stop services with options - `docker\scripts\docker-logs.bat` - View service logs #### Linux/Mac Shell Scripts: - `docker/scripts/docker-start.sh` - Start all services - `docker/scripts/docker-stop.sh` - Stop services with options - `docker/scripts/docker-logs.sh` - View service logs ### 7. **Updated Next.js Configuration** - Enabled standalone output for Docker - Optimized for production builds **Location:** `web-dashboard/next.config.ts` ### 8. **Created Comprehensive Documentation** - Complete Docker setup guide - Architecture diagram - Service management commands - Troubleshooting section - Security best practices - Performance tuning tips **Location:** `DOCKER.md` ### 9. **Updated Main README** - Added Docker deployment section as recommended method - Clear quick start instructions - Links to full documentation **Location:** `README.md` ## πŸ—οΈ Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Docker Network β”‚ β”‚ (trading_bot_network) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Dashboard │────────▢│ Trading API β”‚ β”‚ β”‚ β”‚ (Next.js) β”‚ HTTP β”‚ (FastAPI) β”‚ β”‚ β”‚ β”‚ Port: 3000 β”‚ β”‚ Port: 8000 β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ PostgreSQL β”‚ β”‚ β”‚ Protocol β”‚ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ PostgreSQL β”‚ β”‚ β”‚ β”‚ Database β”‚ β”‚ β”‚ β”‚ Port: 5432 β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” (Optional - Admin Profile) β”‚ β”‚ β”‚ pgAdmin β”‚ β”‚ β”‚ β”‚ Port: 5050 β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↕ Exposed Ports localhost:3000 (Dashboard) localhost:8000 (API) localhost:5432 (Database) localhost:5050 (pgAdmin) ``` ## πŸš€ Quick Start Guide ### 1. Initial Setup (One-time) ```bash # Navigate to project cd "Smart Automatic Trading BOT + AI" # Create environment file copy docker\.env.docker.example .env # Edit .env with your MT5 credentials notepad .env ``` **Required credentials in .env:** ```env MT5_LOGIN=your_login MT5_PASSWORD=your_password MT5_SERVER=your_server MT5_PATH=/path/to/mt5/terminal ``` ### 2. Start Services (Windows) **Option A: Using helper script (Recommended)** ```cmd REM Start core services docker\scripts\docker-start.bat REM Or start with pgAdmin docker\scripts\docker-start.bat --admin ``` **Option B: Manual docker-compose** ```cmd REM Build and start docker-compose up -d REM With pgAdmin docker-compose --profile admin up -d ``` ### 3. Access the Dashboard Open your browser and go to: - **Dashboard:** http://localhost:3000 You'll see: - Real-time price updates - Account balance and equity - Trading signals (SMC + ML) - Market regime - Open positions - Risk status - Activity logs ### 4. Check Other Services - **API Docs:** http://localhost:8000/docs - **API Health:** http://localhost:8000/api/health - **API Status:** http://localhost:8000/api/status - **pgAdmin:** http://localhost:5050 (if started with --admin) ## πŸ“‹ Common Commands ### View Logs ```cmd REM All services docker\scripts\docker-logs.bat REM Specific service docker\scripts\docker-logs.bat trading-api docker\scripts\docker-logs.bat dashboard docker\scripts\docker-logs.bat postgres ``` ### Check Status ```cmd docker-compose ps ``` ### Restart Services ```cmd REM Restart all docker-compose restart REM Restart specific docker-compose restart trading-api docker-compose restart dashboard ``` ### Stop Services ```cmd REM Stop (keeps data) docker\scripts\docker-stop.bat REM Stop and remove containers (keeps data) docker\scripts\docker-stop.bat --remove REM Stop and remove everything including data (⚠️ DANGER!) docker\scripts\docker-stop.bat --clean ``` ### Update Code and Rebuild ```cmd REM Pull latest code git pull REM Rebuild and restart docker-compose build docker-compose up -d ``` ## πŸ”§ Configuration ### Port Configuration Default ports can be changed in `.env`: ```env API_PORT=8000 # Trading API DASHBOARD_PORT=3000 # Web Dashboard DB_PORT=5432 # PostgreSQL PGADMIN_PORT=5050 # pgAdmin ``` ### Environment Variables All configuration is in `.env`: | Category | Variables | |----------|-----------| | **MT5** | MT5_LOGIN, MT5_PASSWORD, MT5_SERVER, MT5_PATH | | **Trading** | SYMBOL, CAPITAL | | **Database** | DB_USER, DB_PASSWORD, DB_NAME | | **Telegram** | TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID | | **Ports** | API_PORT, DASHBOARD_PORT, DB_PORT, PGADMIN_PORT | ## πŸ› Troubleshooting ### Dashboard Shows "Connection Error" **Check if API is running:** ```cmd curl http://localhost:8000/api/health ``` **View API logs:** ```cmd docker\scripts\docker-logs.bat trading-api ``` ### Port Already in Use **Find what's using the port:** ```cmd netstat -ano | findstr :3000 netstat -ano | findstr :8000 ``` **Change port in .env:** ```env DASHBOARD_PORT=3001 API_PORT=8001 ``` **Restart services:** ```cmd docker-compose down docker-compose up -d ``` ### Can't Connect to MT5 1. Check credentials in `.env` 2. Ensure MT5 terminal is accessible 3. View API logs for connection errors: ```cmd docker\scripts\docker-logs.bat trading-api ``` ### Database Connection Issues **Check database health:** ```cmd docker-compose ps postgres ``` **Test connection:** ```cmd docker exec -it trading_bot_db pg_isready -U trading_bot ``` **View database logs:** ```cmd docker\scripts\docker-logs.bat postgres ``` ## πŸ“Š Monitoring ### View Real-time Logs ```cmd REM Follow all logs docker-compose logs -f REM Follow specific service docker-compose logs -f trading-api ``` ### Check Resource Usage ```cmd docker stats ``` ### Service Health ```cmd REM All services docker-compose ps REM Detailed info docker inspect trading_bot_api docker inspect trading_bot_dashboard ``` ## πŸ” Security Notes 1. **Never commit .env file** - It contains sensitive credentials 2. **Change default passwords** - Especially for database and pgAdmin 3. **Use strong passwords** - For all services 4. **Limit port exposure** - Only expose ports you need 5. **Keep Docker updated** - Regular security updates ## πŸ“ File Structure ``` xaubot-ai/ β”œβ”€β”€ Dockerfile # Python API Docker image β”œβ”€β”€ docker-compose.yml # Service orchestration β”œβ”€β”€ .env # Environment variables (DO NOT COMMIT) β”œβ”€β”€ .dockerignore # Files to exclude from build β”œβ”€β”€ docker/ β”‚ β”œβ”€β”€ .env.docker.example # Environment template β”‚ β”œβ”€β”€ requirements-docker.txt # Docker-specific Python deps β”‚ β”œβ”€β”€ init-db/01-schema.sql # Database schema β”‚ β”œβ”€β”€ scripts/ # Helper scripts β”‚ β”‚ β”œβ”€β”€ docker-start.bat/.sh β”‚ β”‚ β”œβ”€β”€ docker-stop.bat/.sh β”‚ β”‚ β”œβ”€β”€ docker-logs.bat/.sh β”‚ β”‚ β”œβ”€β”€ docker-status.bat β”‚ β”‚ β”œβ”€β”€ docker-add-dashboard.bat β”‚ β”‚ β”œβ”€β”€ docker-remove-dashboard.bat β”‚ β”‚ β”œβ”€β”€ start-all.bat β”‚ β”‚ β”œβ”€β”€ start-api.bat β”‚ β”‚ └── start-dashboard.bat β”‚ └── docs/ # Docker documentation β”‚ β”œβ”€β”€ DOCKER.md β”‚ β”œβ”€β”€ DOCKER-INTEGRATION.md β”‚ β”œβ”€β”€ DOCKER-SETUP-SUMMARY.md β”‚ β”œβ”€β”€ QUICK-START.md β”‚ └── SIMPLE-START.md └── web-dashboard/ β”œβ”€β”€ Dockerfile # Next.js dashboard image β”œβ”€β”€ .dockerignore # Dashboard build exclusions └── next.config.ts # Next.js config (standalone output) ``` ## 🎯 Benefits of Docker Setup βœ… **Easy Setup** - One command to start everything βœ… **Consistent Environment** - Same setup on any machine βœ… **Isolated Services** - No conflicts with other software βœ… **Easy Updates** - Rebuild and restart to update βœ… **Production Ready** - Same setup for dev and production βœ… **Automatic Restarts** - Services auto-restart on crash βœ… **Health Monitoring** - Built-in health checks βœ… **Volume Persistence** - Data survives container restarts ## πŸ“š Additional Resources - **Full Documentation:** [DOCKER.md](DOCKER.md) - **Styling Guide:** [web-dashboard/STYLING-GUIDE.md](web-dashboard/STYLING-GUIDE.md) - **Docker Docs:** https://docs.docker.com - **Docker Compose:** https://docs.docker.com/compose ## πŸ†˜ Support If you encounter issues: 1. Check the logs: `docker\scripts\docker-logs.bat` 2. Verify services: `docker-compose ps` 3. Review troubleshooting section in [DOCKER.md](DOCKER.md) 4. Check service health: `curl http://localhost:8000/api/health` --- **Setup completed:** Feb 6, 2026 **Ready to deploy!** πŸš€