> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wryft.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Docker Deployment

> Deploy Wryft Chat with Docker and Docker Compose

## Overview

The easiest way to deploy Wryft Chat is using Docker Compose.

## Prerequisites

* Docker 20.10+
* Docker Compose 2.0+
* 2GB RAM minimum
* 10GB storage

## Quick Deploy

<Steps>
  <Step title="Clone repository">
    ```bash theme={null}
    git clone https://github.com/Warehouser-dev/wryft-chat.git
    cd wryft-chat
    ```
  </Step>

  <Step title="Configure environment">
    ```bash theme={null}
    cp backend/.env.example backend/.env
    cp wryft-web/.env.example wryft-web/.env
    ```

    Edit the `.env` files with your configuration.
  </Step>

  <Step title="Start services">
    ```bash theme={null}
    docker-compose up -d
    ```
  </Step>

  <Step title="Run migrations">
    ```bash theme={null}
    docker-compose exec backend psql -d wryft -f /app/migrations/*.sql
    ```
  </Step>
</Steps>

## Docker Compose Services

The `docker-compose.yml` includes:

### Backend

* Rust API server
* Port: 3001
* Auto-restarts on failure

### Frontend

* Nginx serving React app
* Port: 80
* Gzip compression enabled

### PostgreSQL

* Database server
* Port: 5432
* Persistent volume

### MinIO

* S3-compatible storage
* Port: 9000 (API), 9001 (Console)
* Persistent volume

### Redis

* Cache server
* Port: 6379
* Optional (for performance)

## Configuration

### Backend Environment

```env theme={null}
DATABASE_URL=postgresql://postgres:password@postgres:5432/wryft
REDIS_URL=redis://redis:6379
S3_ENDPOINT=http://minio:9000
S3_ACCESS_KEY=minioadmin
S3_SECRET_KEY=minioadmin
S3_BUCKET=wryft
PORT=3001
```

### Frontend Environment

```env theme={null}
VITE_API_URL=http://your-domain.com/api
VITE_WS_URL=ws://your-domain.com
```

## Nginx Configuration

The included `nginx.conf` provides:

* Reverse proxy to backend
* WebSocket support
* Gzip compression
* Static file serving
* CORS headers

## Volumes

Persistent data is stored in:

* `postgres_data` - Database
* `minio_data` - File uploads
* `redis_data` - Cache

## Scaling

### Horizontal Scaling

Scale backend instances:

```bash theme={null}
docker-compose up -d --scale backend=3
```

Add load balancer (nginx/traefik) in front.

### Vertical Scaling

Increase resources in `docker-compose.yml`:

```yaml theme={null}
services:
  backend:
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 2G
```

## Monitoring

### View Logs

```bash theme={null}
# All services
docker-compose logs -f

# Specific service
docker-compose logs -f backend
```

### Health Checks

```bash theme={null}
# Backend health
curl http://localhost:3001/api/health

# Database
docker-compose exec postgres pg_isready
```

## Backup

### Database Backup

```bash theme={null}
docker-compose exec postgres pg_dump -U postgres wryft > backup.sql
```

### Restore Database

```bash theme={null}
docker-compose exec -T postgres psql -U postgres wryft < backup.sql
```

### MinIO Backup

```bash theme={null}
docker-compose exec minio mc mirror /data/wryft /backup/wryft
```

## Updating

```bash theme={null}
# Pull latest code
git pull

# Rebuild containers
docker-compose build

# Restart services
docker-compose up -d
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Container won't start">
    Check logs: `docker-compose logs backend`
  </Accordion>

  <Accordion title="Database connection failed">
    Verify PostgreSQL is running: `docker-compose ps postgres`
  </Accordion>

  <Accordion title="Out of memory">
    Increase Docker memory limit in Docker Desktop settings
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Production Setup" icon="rocket" href="/deployment/production">
    Production deployment guide
  </Card>

  <Card title="Environment Variables" icon="gear" href="/deployment/environment">
    Full configuration reference
  </Card>
</CardGroup>
