# Lottery Investment Calculator - Docker Setup ## Prerequisites - Docker Desktop installed (https://www.docker.com/products/docker-desktop) - Docker Compose (included with Docker Desktop) --- ## Quick Start ### 1. Configure Environment ```bash cp .env.example .env # Edit .env with your preferred settings ``` ### 2. Build and Run ```bash docker compose up -d ``` This starts: - **Backend API** on http://localhost:5000 - **Frontend Web App** on http://localhost:3000 ### 3. Check Status ```bash docker compose ps ``` ### 4. View Logs ```bash # All services docker compose logs -f # Specific service docker compose logs -f backend docker compose logs -f frontend ``` ### 5. Stop ```bash docker compose down ``` --- ## Individual Services ### Backend Only ```bash docker build -f Dockerfile.backend -t lottery-backend . docker run -p 5000:5000 --env-file .env lottery-backend ``` ### Frontend Only ```bash docker build -f Dockerfile.frontend -t lottery-frontend . docker run -p 3000:3000 lottery-frontend ``` --- ## Configuration All configuration is done via environment variables. See `.env.example` for available options. Key variables: | Variable | Default | Description | |----------|---------|-------------| | `FLASK_DEBUG` | `false` | Enable Flask debug mode | | `FLASK_CORS_ORIGINS` | `*` | Allowed CORS origins | | `FEDERAL_TAX_RATE` | `0.37` | US federal tax rate | | `DEFAULT_STATE_TAX_RATE` | `0.055` | Default state tax rate | | `USD_TO_CAD` | `1.44` | USD→CAD exchange rate | | `CACHE_TTL_HOURS` | `6` | Jackpot cache duration | --- ## Network ### Internal URLs (container to container) - Backend: `http://backend:5000` - Frontend: `http://frontend:3000` ### External URLs (host machine) - Backend: `http://localhost:5000` - Frontend: `http://localhost:3000` --- ## Health Checks ```bash curl http://localhost:5000/api/health ``` --- ## Production Deployment ### Using Production Compose ```bash docker compose -f docker-compose.prod.yml up -d ``` This adds nginx reverse proxy with: - Rate limiting (10 req/s) - Static asset caching - HTTPS support (configure certs in `ssl/`) - Resource limits per container See `ssl/README.md` for certificate setup. ### Deploy to Server ```bash git clone cd Lottery-Tracker cp .env.example .env # Edit .env for production docker compose -f docker-compose.prod.yml up -d ``` ### Push to Docker Hub ```bash docker login docker tag lottery-backend yourusername/lottery-backend:latest docker tag lottery-frontend yourusername/lottery-frontend:latest docker push yourusername/lottery-backend:latest docker push yourusername/lottery-frontend:latest ``` --- ## Troubleshooting ### Port Already in Use ```bash # Windows netstat -ano | findstr :5000 taskkill /PID /F # Or change ports in docker-compose.yml ``` ### Backend Won't Start ```bash docker logs lottery-backend docker compose build --no-cache backend ``` ### Frontend Can't Connect to Backend ```bash docker compose ps curl http://localhost:5000/api/health docker exec lottery-frontend env | grep API_URL ``` ### Playwright Browser Issues ```bash docker compose build --no-cache backend docker exec lottery-backend playwright --version ``` ### Access Container Shell ```bash docker exec -it lottery-backend /bin/bash docker exec -it lottery-frontend /bin/sh ``` ### Clean Everything ```bash docker compose down -v --rmi all docker system prune -a ``` --- ## Resource Usage Production limits (set in `docker-compose.prod.yml`): - Backend: 2 GB RAM, 1 CPU - Frontend: 512 MB RAM, 0.5 CPU - Nginx: 256 MB RAM, 0.25 CPU ### Monitor ```bash docker stats ``` --- ## Image Sizes (Approximate) - Backend: ~1.5 GB (includes Chromium for Playwright) - Frontend: ~200 MB (Next.js standalone) - Nginx: ~30 MB