# 🐳 Docker Quick Start

## TL;DR - Run This

```bash
# 1. Make sure Docker Desktop is running (check menu bar)

# 2. Run automated test script
./test-docker.sh

# 3. Open in browser
# http://localhost:5173
```

## Manual Steps

```bash
# Clean slate
docker compose down -v

# Build and start
docker compose build
docker compose up -d

# Watch logs
docker compose logs -f

# Stop when done
docker compose down
```

## Test Credentials

```
Email: alice@example.com
Password: password123
```

Also available: bob@example.com, charlie@example.com

## URLs

- **Frontend**: http://localhost:5173
- **Backend API**: http://localhost:8000/docs
- **WebSocket**: ws://localhost:8000/api/v1/ws

## What to Check

In the browser at http://localhost:5173:

1. ✅ Login works
2. ✅ Blockchain badges (⛓️) on bet cards
3. ✅ "Connect Wallet" button in header
4. ✅ Gas estimate in Create Bet modal
5. ✅ "On-Chain Escrow" in Wallet page

## Quick Commands

```bash
# Container status
docker compose ps

# View logs
docker compose logs -f

# Restart a service
docker compose restart backend
docker compose restart frontend

# Run command in container
docker compose exec backend python seed_data.py
docker compose exec backend bash
docker compose exec frontend sh

# Stop everything
docker compose down

# Nuclear option (remove everything)
docker compose down -v && docker system prune -f
```

## Troubleshooting

### Port already in use
```bash
lsof -ti:5173 | xargs kill -9
lsof -ti:8000 | xargs kill -9
docker compose up -d
```

### Database issues
```bash
docker compose down -v
docker compose up -d
docker compose exec backend python seed_data.py
```

### Can't connect
```bash
# Check containers are running
docker compose ps

# Check logs for errors
docker compose logs backend | tail -50
docker compose logs frontend | tail -50
```

### Rebuild everything
```bash
docker compose down -v
docker compose build --no-cache
docker compose up -d
```

## File Locations in Containers

### Backend Container
```
/app/
├── app/
│   ├── blockchain/
│   │   ├── contracts/        # Smart contract pseudocode
│   │   ├── services/         # Web3 integration
│   │   └── config.py
│   ├── models/               # Database models (with blockchain fields)
│   └── ...
└── data/
    └── h2h.db                # SQLite database
```

### Frontend Container
```
/app/
├── src/
│   ├── blockchain/
│   │   ├── hooks/            # Web3 React hooks
│   │   └── components/       # Blockchain UI components
│   ├── components/           # Modified with blockchain features
│   └── types/                # TypeScript types
└── node_modules/
```

## Health Check Commands

```bash
# Backend health
curl http://localhost:8000/docs

# Frontend health
curl http://localhost:5173

# Login test
curl -X POST http://localhost:8000/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "alice@example.com", "password": "password123"}'
```

## Development Workflow

```bash
# Start services
docker compose up -d

# Make code changes in your editor
# (Changes auto-reload thanks to volume mounts)

# Watch logs
docker compose logs -f

# When done
docker compose down
```

## Advanced: Individual Service Control

```bash
# Start only backend
docker compose up -d backend

# Start only frontend
docker compose up -d frontend

# Scale frontend (for load testing)
docker compose up -d --scale frontend=3

# Follow specific service logs
docker compose logs -f backend
```

## Resource Monitoring

```bash
# See resource usage
docker stats

# See disk usage
docker system df

# Clean up unused images/containers
docker system prune -f
```

## Complete Reset

If something goes wrong, nuclear option:

```bash
# Stop everything
docker compose down -v

# Remove all Docker data (CAUTION: affects all projects)
docker system prune -a --volumes -f

# Rebuild from scratch
docker compose build --no-cache
docker compose up -d
```

---

📖 For detailed guide: See `DOCKER_TESTING_GUIDE.md`

🤖 Automated testing: Run `./test-docker.sh`
