# 📦 MEDIX Q - Docker Files Reference

## Container Configuration Files

### 1. **Dockerfile** (Production)
- Optimized image for production deployments
- Based on Node.js 18 Alpine (lightweight)
- Builds the Next.js application once
- Size: ~380MB

```dockerfile
# Production multi-stage build
FROM node:18-alpine
# Installs dependencies
# Builds Next.js app
# Exposes port 3000
# Starts with: pnpm start
```

**Use when:** Deploying to production

---

### 2. **Dockerfile.dev** (Development)
- Development image with hot reload support
- Faster iteration during development
- Includes WATCHPACK_POLLING for file watching

```dockerfile
# Development build
FROM node:18-alpine
# Installs dependencies (no frozen-lockfile)
# Exposes port 3000
# Starts with: pnpm dev
```

**Use when:** Local development with code changes

---

## Docker Compose Files

### 3. **docker-compose.yml** (Production)
```yaml
version: '3.8'
services:
  medix-q:
    # Builds from Dockerfile
    # Exposes port 3000
    # Mounts ./data volume for persistence
    # Includes health checks
    # Auto-restart on failure
```

**Features:**
- Single service setup
- Data persistence with volumes
- Health check every 30 seconds
- Automatic restart policy
- Production environment variables

**Start:** `docker-compose up -d`

---

### 4. **docker-compose.dev.yml** (Development)
```yaml
version: '3.8'
services:
  medix-q-dev:
    # Builds from Dockerfile.dev
    # Exposes port 3000
    # Mounts entire project for hot reload
    # Sets development environment
```

**Features:**
- Full source code mounted
- Node modules excluded (volume)
- Development mode enabled
- Hot reload on file changes
- Real-time log output

**Start:** `docker-compose -f docker-compose.dev.yml up`

---

## Startup Scripts

### 5. **docker-start.sh** (macOS/Linux)
Interactive shell script for easy Docker management

```bash
chmod +x docker-start.sh

# Usage:
./docker-start.sh                 # Start production
./docker-start.sh dev             # Start development
./docker-start.sh stop            # Stop containers
./docker-start.sh logs            # View logs
./docker-start.sh rebuild         # Rebuild and restart
```

**Features:**
- Automatic Docker/Docker Compose detection
- Mode selection (production/development)
- Simple commands for common tasks
- Helpful error messages
- Usage examples

---

### 6. **docker-start.bat** (Windows)
Interactive batch script for Windows users

```cmd
# Usage:
docker-start.bat                  # Start production
docker-start.bat dev              # Start development
docker-start.bat stop             # Stop containers
docker-start.bat logs             # View logs
docker-start.bat rebuild          # Rebuild and restart
```

**Features:**
- Windows CMD compatible
- Same functionality as shell script
- User-friendly prompts
- Clear error messages

---

## Utility Files

### 7. **.dockerignore**
Excludes files from Docker build context

```
node_modules/
npm-debug.log
.git/
.gitignore
README.md
.next/
.vercel/
.env.local
.DS_Store
dist/
build/
coverage/
.turbo/
```

**Purpose:** Reduces image size and build time

---

### 8. **verify-docker.sh** (Verification Script)
Pre-flight checks before running Docker

```bash
chmod +x verify-docker.sh
./verify-docker.sh
```

**Checks:**
- Docker installation
- Docker Compose availability
- Docker daemon running
- Disk space availability
- Port 3000 availability
- Required files present

**Output:** Pass/fail summary with fixes

---

## Documentation Files

### 9. **README_DOCKER.md** (Comprehensive Guide)
Complete Docker setup and reference documentation

**Sections:**
- Quick start options
- Installation requirements
- Running MEDIX Q
- Development vs Production
- Common commands
- Troubleshooting guide
- Advanced configuration
- Monitoring and health checks
- Verification checklist

**Read:** Complete guide for all Docker operations

---

### 10. **QUICKSTART_DOCKER.md** (Quick Reference)
Fast 3-minute startup guide

**Sections:**
- Step-by-step startup
- Common commands
- Troubleshooting tips
- Feature highlights

**Read:** When you just want to get started

---

### 11. **DOCKER_SETUP.md** (Setup Documentation)
Detailed Docker setup instructions

**Sections:**
- Quick start methods
- Prerequisites
- Common commands
- Data persistence
- Environment variables
- Production deployment
- Troubleshooting

---

## File Organization

```
medix-q/
├── 📄 Dockerfile                 # Production image
├── 📄 Dockerfile.dev             # Development image
├── 📄 docker-compose.yml         # Production compose
├── 📄 docker-compose.dev.yml     # Development compose
├── 📄 .dockerignore              # Build exclusions
├── 🔧 docker-start.sh            # Linux/macOS startup
├── 🔧 docker-start.bat           # Windows startup
├── 🔧 verify-docker.sh           # Verification tool
├── 📖 README_DOCKER.md           # Full guide
├── 📖 QUICKSTART_DOCKER.md       # Quick start
├── 📖 DOCKER_SETUP.md            # Setup guide
└── 📖 DOCKER_FILES.md            # This file
```

---

## Quick Reference

| Task | Command |
|------|---------|
| **Verify setup** | `./verify-docker.sh` |
| **Start production** | `./docker-start.sh` |
| **Start development** | `./docker-start.sh dev` |
| **Stop all containers** | `./docker-start.sh stop` |
| **View logs** | `docker-compose logs -f` |
| **Access shell** | `docker-compose exec medix-q-app sh` |
| **Rebuild image** | `./docker-start.sh rebuild` |
| **Clean everything** | `docker-compose down -v` |

---

## Environment Variables

### Production
```env
NODE_ENV=production
PORT=3000
```

### Development
```env
NODE_ENV=development
PORT=3000
WATCHPACK_POLLING=true
```

---

## Port Configuration

- **Default:** `3000` (host) → `3000` (container)
- **To change:** Edit `docker-compose.yml`
  ```yaml
  ports:
    - "3001:3000"  # Access at localhost:3001
  ```

---

## Volume Mounts

### Production
```yaml
volumes:
  - ./data:/app/.data  # Persistent JSON database
```

### Development
```yaml
volumes:
  - .:/app                    # Entire project
  - /app/node_modules         # Exclude node_modules
  - ./data:/app/.data         # Persistent data
```

---

## Troubleshooting Files

- **Docker logs:** `docker-compose logs`
- **System logs:** Check Docker Desktop app logs
- **Data file:** `./data/medix_q.json`
- **Build errors:** Run `./docker-start.sh rebuild`

---

## Getting Help

1. Run verification: `./verify-docker.sh`
2. Check logs: `docker-compose logs -f`
3. Read full guide: `README_DOCKER.md`
4. Troubleshooting: `README_DOCKER.md#troubleshooting`

---

## Summary

| File | Purpose | When to Use |
|------|---------|------------|
| Dockerfile | Production image | Production deployment |
| Dockerfile.dev | Development image | Local development |
| docker-compose.yml | Production setup | Running production |
| docker-compose.dev.yml | Development setup | Local development |
| docker-start.sh | Easy startup (Linux/Mac) | Preferred method |
| docker-start.bat | Easy startup (Windows) | Windows preferred |
| verify-docker.sh | Pre-flight checks | Before first run |
| README_DOCKER.md | Complete reference | Full documentation |
| QUICKSTART_DOCKER.md | Fast guide | Quick reference |

---

All files are ready to use. Start with `./verify-docker.sh` then `./docker-start.sh`! 🚀
