# Docker Quick Reference

## 🚀 Quick Start

```powershell
# Enable BuildKit (first time only)
$env:DOCKER_BUILDKIT=1
$env:COMPOSE_DOCKER_CLI_BUILD=1

# Build and start
./docker-helper.ps1 build
./docker-helper.ps1 start
```

**Access Points:**
- Frontend: http://localhost:3000
- Backend: http://localhost:8080
- Database: localhost:5432

## 📋 Common Commands

```powershell
# Using helper script (recommended)
./docker-helper.ps1 start      # Start all services
./docker-helper.ps1 stop       # Stop all services
./docker-helper.ps1 restart    # Restart services
./docker-helper.ps1 logs       # View logs
./docker-helper.ps1 stats      # Check resources
./docker-helper.ps1 clean      # Cleanup

# Individual services
./docker-helper.ps1 restart backend
./docker-helper.ps1 logs frontend
```

## 🔧 Manual Docker Commands

```powershell
# Build
docker-compose build                    # All services
docker-compose build backend            # Single service
docker-compose build --no-cache         # Force rebuild

# Start/Stop
docker-compose up -d                    # Start detached
docker-compose down                     # Stop and remove
docker-compose restart                  # Restart all

# Logs
docker-compose logs -f                  # Follow all logs
docker-compose logs -f backend          # Single service
docker-compose logs --tail=50 backend   # Last 50 lines

# Status
docker-compose ps                       # List containers
docker stats                            # Resource usage
docker-compose config                   # Verify config
```

## 🗄️ Database Operations

```powershell
# Connect to PostgreSQL
docker exec -it myclub-db psql -U postgres -d fotbal_club

# Backup database
docker exec myclub-db pg_dump -U postgres fotbal_club > backup.sql

# Restore database
docker exec -i myclub-db psql -U postgres fotbal_club < backup.sql

# Check database settings
docker exec myclub-db psql -U postgres -c "SHOW shared_buffers;"
```

## 📊 Monitoring

```powershell
# Resource usage
docker stats --no-stream                # Snapshot
docker stats                            # Live monitoring

# Container details
docker inspect myclub-backend           # Full details
docker top myclub-backend               # Processes

# Disk usage
docker system df                        # Disk usage
docker system df -v                     # Detailed view
```

## 🧹 Cleanup

```powershell
# Gentle cleanup (keeps images)
./docker-helper.ps1 clean

# Remove everything
./docker-helper.ps1 reset

# Manual cleanup
docker-compose down -v                  # Remove volumes
docker system prune -f                  # Remove unused
docker builder prune -f                 # Clear build cache
docker volume prune -f                  # Remove volumes
```

## 🐛 Troubleshooting

```powershell
# Check BuildKit
docker buildx version

# View container logs
docker logs myclub-backend
docker logs myclub-frontend
docker logs myclub-db

# Restart a service
docker-compose restart backend

# Rebuild a service
docker-compose up -d --build backend

# Check health
docker inspect myclub-backend | Select-String -Pattern "Health"
```

## ⚙️ Configuration Files

| File | Purpose |
|------|---------|
| `docker-compose.yml` | Main configuration |
| `docker-compose.override.yml` | Development overrides |
| `Dockerfile.dev` | Backend build |
| `frontend/Dockerfile` | Frontend build |
| `.dockerignore` | Build context exclusions |

## 📈 Performance Tips

1. **Always use BuildKit** for faster builds
2. **Don't use `--no-cache`** unless necessary
3. **Monitor with `docker stats`** regularly
4. **Clean up periodically** with `./docker-helper.ps1 clean`
5. **Check logs** if services are slow: `./docker-helper.ps1 logs`

## 🎯 Resource Limits

| Service | CPU Max | Memory Max | Typical Usage |
|---------|---------|------------|---------------|
| Backend | 2.0 | 1GB | ~200-300MB |
| Frontend | 1.0 | 512MB | ~50-100MB |
| Database | 2.0 | 2GB | ~500-800MB |

## 🔍 Health Checks

```powershell
# Backend health
curl http://localhost:8080/api/v1/health

# Database health  
docker exec myclub-db pg_isready -U postgres

# All services status
docker-compose ps
```

## 📝 Environment Variables

```powershell
# Required for BuildKit
$env:DOCKER_BUILDKIT=1
$env:COMPOSE_DOCKER_CLI_BUILD=1

# Optional for debugging
$env:COMPOSE_DOCKER_CLI_BUILD_EXTRA_ARGS="--progress=plain"
```

## 🆘 Emergency Commands

```powershell
# Stop everything immediately
docker stop $(docker ps -q)

# Kill hanging containers
docker kill $(docker ps -q)

# Full system reset (DANGEROUS!)
docker system prune -af --volumes

# Reset network
docker network prune -f
docker-compose down
docker-compose up -d
```

## 📖 Documentation

- `DOCKER_PERFORMANCE_GUIDE.md` - Detailed guide
- `DOCKER_ENHANCEMENTS_SUMMARY.md` - Changes summary
- `docker-helper.ps1` - Helper script source

## 🎓 Next Steps

1. Read `DOCKER_PERFORMANCE_GUIDE.md` for deep dive
2. Customize resource limits in `docker-compose.yml` if needed
3. Set up monitoring with `docker stats`
4. Optimize database settings for your workload
