# MEDIX Q - Docker Setup Guide

## Quick Start with Docker

### Prerequisites
- Docker installed on your system ([Download Docker](https://www.docker.com/products/docker-desktop))
- Docker Compose (comes with Docker Desktop)

### Option 1: Using Docker Compose (Recommended)

The easiest way to run MEDIX Q is with Docker Compose:

```bash
# Build and start the application
docker-compose up -d

# View logs
docker-compose logs -f

# Stop the application
docker-compose down
```

The application will be available at `http://localhost:3000`

### Option 2: Using Docker Directly

Build the Docker image:

```bash
docker build -t medix-q .
```

Run the container:

```bash
docker run -d \
  --name medix-q \
  -p 3000:3000 \
  -v $(pwd)/data:/app/.data \
  medix-q
```

Access the application at `http://localhost:3000`

### Option 3: Building for Development

For development with hot reload, use the development docker-compose file:

```bash
docker-compose -f docker-compose.dev.yml up
```

## Data Persistence

The application stores data in a JSON file at `.data/medix_q.json`. This data is persisted through Docker volumes:

```yaml
volumes:
  - ./data:/app/.data
```

Your data will survive container restarts and be accessible from your host machine in the `./data` directory.

## Environment Variables

The following environment variables can be customized:

```bash
NODE_ENV=production  # Set to 'development' for development builds
PORT=3000           # Port to run the application on
```

To override these, update the `docker-compose.yml` file or pass them with `-e` flag:

```bash
docker run -d -p 3000:3000 -e NODE_ENV=development medix-q
```

## Common Commands

### View running containers
```bash
docker ps
```

### View container logs
```bash
docker logs -f medix-q-app
```

### Access container shell
```bash
docker exec -it medix-q-app sh
```

### Rebuild the image
```bash
docker-compose down
docker-compose build --no-cache
docker-compose up -d
```

### Clean up
```bash
# Stop and remove containers
docker-compose down

# Remove images
docker rmi medix-q:latest

# Remove all unused Docker resources
docker system prune -a
```

## Troubleshooting

### Port already in use
If port 3000 is already in use, modify `docker-compose.yml`:

```yaml
ports:
  - "3001:3000"  # Change host port to 3001
```

### Permission denied errors
Ensure the `.data` directory has proper permissions:

```bash
chmod 755 ./data
```

### Application not responding
Check the logs:

```bash
docker-compose logs medix-q
```

## Performance Notes

- The first build may take 5-10 minutes depending on your internet speed
- Subsequent builds are faster due to Docker layer caching
- The container runs on Alpine Linux (lightweight ~380MB image)
- Data is persisted in JSON format for simplicity

## Production Deployment

For production use, consider:

1. Using a proper database instead of JSON storage
2. Setting up proper environment variables via `.env` file
3. Using a reverse proxy (nginx) for SSL/TLS
4. Setting up monitoring and logging
5. Using orchestration tools like Kubernetes

Example production docker-compose:

```yaml
version: '3.8'
services:
  medix-q:
    build: .
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
    volumes:
      - ./data:/app/.data
      - ./logs:/app/logs
    restart: always
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 512M
```

## Support

For issues or questions, check the logs and ensure all dependencies are properly installed within the container.
