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

# Docker Deployment

> Deploy ChatterMate with Docker in development or production, running the frontend, FastAPI backend, PostgreSQL with pgvector, and Redis through Docker Compose.

# Docker Deployment

ChatterMate can be deployed using Docker in both development and production environments.

## Development Setup

For local development, we use `docker-compose.yml` which sets up:

* Frontend (Vue.js) with hot-reloading
* Backend (FastAPI) with auto-reload
* PostgreSQL with pgvector extension
* Redis for caching and rate limiting

### Prerequisites

* Docker
* Docker Compose
* Git

### Quick Start

1. Clone the repository:

```bash theme={null}
git clone https://github.com/chattermate/chattermate.chat
cd chattermate.chat
```

2. Create environment files:

```bash theme={null}
# Frontend environment
cp frontend/.env.example frontend/.env

# Backend environment
cp backend/.env.example backend/.env
```

3. Start the development environment:

```bash theme={null}
docker-compose up --build
```

Services will be available at:

* Frontend: [http://localhost:3000](http://localhost:3000)
* Backend API: [http://localhost:8000](http://localhost:8000)
* Backend Docs: [http://localhost:8000/docs](http://localhost:8000/docs)
* PostgreSQL: localhost:5432
* Redis: localhost:6379

### Development Features

* Hot-reloading for frontend changes
* Auto-reload for backend changes
* Volume mounts for live code updates
* Development-mode Firebase credentials
* Automatic database migrations
* Health checks for all services

## Production Deployment

For production deployment, we use `docker-compose.prod.yml` which provides:

* Optimized multi-stage builds
* Nginx for frontend serving
* Gunicorn for backend serving
* Production-grade configurations
* Health monitoring
* Automatic restarts

### Production Setup

1. Set up environment files:

```bash theme={null}
# Frontend production environment
cp frontend/.env.prod.example frontend/.env

# Backend production environment
cp backend/.env.prod.example backend/.env
```

2. Configure Firebase (Optional):

```bash theme={null}
# Place your Firebase credentials in
./config/firebase-credentials.json
```

3. Start production services:

```bash theme={null}
docker-compose -f docker-compose.prod.yml up -d
```

### Production Features

* Multi-stage builds for smaller images
* Nginx configuration for frontend
* Gunicorn with multiple workers
* Redis persistence
* Database backups
* Automatic health checks
* Container restart policies

## Docker Images

### Frontend Images

* Development: `Dockerfile.frontend`
  * Node.js development server
  * Hot-reloading enabled
  * Volume mounts for live updates

* Production: `Dockerfile.frontend.prod`
  * Multi-stage build
  * Nginx for static file serving
  * Optimized build size
  * Health monitoring

### Backend Images

* Development: `Dockerfile`
  * Python development server
  * Auto-reload enabled
  * Debug mode

* Production: `Dockerfile.backend.prod`
  * Multi-stage build
  * Gunicorn server
  * Optimized dependencies
  * Worker configuration

### Database Image

* Custom PostgreSQL image with pgvector
* Vector similarity search support
* Automatic initialization
* Health checks

## Environment Variables

### Frontend Variables

```env theme={null}
VITE_API_URL=http://localhost:8000
VITE_WS_URL=ws://localhost:8000
```

### Backend Variables

```env theme={null}
DATABASE_URL=postgresql://postgres:postgres@db:5432/chattermate
CORS_ORIGINS=["http://localhost:3000"]
FIREBASE_CREDENTIALS=/app/config/firebase-credentials.json
```

### Production Additional Variables

```env theme={null}
REDIS_ENABLED=true
REDIS_URL=redis://redis:6379/0
WORKERS=4
TIMEOUT=120
LOG_LEVEL=info
```

## Health Checks

All services include health checks:

* Frontend: Checks HTTP endpoint
* Backend: Monitors API health
* PostgreSQL: Verifies database connection
* Redis: Ensures cache availability

## Volumes

Persistent data is managed through Docker volumes:

* `postgres_data`: Database files
* `redis_data`: Cache data
* `backend_data`: Uploaded files
* `frontend_node_modules`: NPM packages

## Networks

Services communicate through Docker networks:

* Development: `app-network`
* Production: `chattermate-network`

## Monitoring

Monitor your deployment using Docker commands:

```bash theme={null}
# View all logs
docker-compose logs -f

# Service-specific logs
docker-compose logs -f frontend
docker-compose logs -f backend
docker-compose logs -f db
docker-compose logs -f redis

# Container health
docker ps
```

## Keeping inference self-hosted

Self-hosting the stack still sends prompts to a hosted AI provider by default. To keep
model inference in your own infrastructure too, configure the **OpenAI-compatible**
provider and give ChatterMate the base URL of your own endpoint — Ollama, vLLM, or
llama.cpp locally, or a gateway such as OpenRouter or LiteLLM.

> [card] [Self-hosted and gateway models](https://docs.chattermate.chat/deployment/self-hosted-models.md)
>
> Worked setups, Docker networking, and the tool-calling caveats

> [!NOTE]
>
> The base URL is resolved from inside the **backend container**, so `localhost` points
> at the container, not your host. Use `host.docker.internal` or a Compose service name
> instead.

## Help Center custom domains (self-hosted)

The [Help Center](https://docs.chattermate.chat/features/help-center.md) can be served on your customers' own
domains with automatic HTTPS. The `chattermate-deploy` CLI bundles a **Caddy edge
proxy** that terminates TLS and issues certificates automatically — no manual
`certbot` or nginx.

**1. Deploy with a domain**

Run `chattermate-deploy init` and answer **yes** to the domain prompt. Enter your
app domain (e.g. `app.example.com`) and, optionally, a Help Center base domain
(e.g. `help.example.com`) for org subdomains. Then `chattermate-deploy start`.

**2. Point DNS at your server**

Add an **A/AAAA** record for your app domain to the server's IP. For Help Center
org subdomains, add a wildcard `*.help.example.com` A/AAAA record too. Certificates
are issued automatically on the first HTTPS request.

**3. Add a customer's custom domain**

In **Customization → Custom domain**, add the domain and create the **TXT** record
shown. Add a **CNAME** from the customer's domain to your **app domain** (which
already resolves to your server), then click **Verify**.

Under the hood the edge only requests a certificate for a hostname the backend
confirms it serves (a verified custom domain or an org subdomain), so a random
domain pointed at your server cannot trigger certificate issuance.

### TLS options

When you give `init` a domain, it asks how HTTPS should be handled:

* **Automatic** *(default)* — Caddy obtains and renews free Let's Encrypt
  certificates, and issues Help Center custom-domain certs on demand.
* **Bring your own certificate** — provide a cert + key (PEM); they're copied
  into `./certs` and served by Caddy, with no calls to Let's Encrypt. For Help
  Center domains, add a block per domain (or a wildcard) — the generated
  `Caddyfile` includes a commented example.
* **Terminated upstream** — your own reverse proxy / load balancer handles TLS
  and forwards plain HTTP to the stack. It **must preserve the `Host` header** so
  the backend can dispatch Help Center domains.

> [!NOTE]
>
> Renewal is automatic — Caddy renews certificates well before expiry with no
> cron or certbot. Certificates and the ACME account are stored in the
> `caddy_data` Docker volume, so keep it across restarts and upgrades — deleting
> it forces re-issuance and can hit Let's Encrypt rate limits. If a custom domain
> sits behind Cloudflare, set the record to **DNS only** (grey cloud) for
> verification, or the CNAME check fails.

## Troubleshooting

Common issues and solutions:

1. Frontend not starting:

```bash theme={null}
# Check frontend logs
docker-compose logs frontend

# Rebuild frontend
docker-compose build --no-cache frontend
```

2. Backend migrations failing:

```bash theme={null}
# Check backend logs
docker-compose logs backend

# Manual migration
docker-compose exec backend alembic upgrade head
```

3. Database connection issues:

```bash theme={null}
# Check database logs
docker-compose logs db

# Verify database health
docker-compose exec db pg_isready -U postgres
```

4. Redis connection issues:

```bash theme={null}
# Check Redis logs
docker-compose logs redis

# Verify Redis connection
docker-compose exec redis redis-cli ping
```

5. Backend build fails with `No space left on device` or pip `ReadTimeoutError`:

The backend image pulls several GB of ML wheels (torch, opencv, onnxruntime),
and the amd64/x86\_64 wheels are noticeably larger than the arm64 ones. On a
small root volume the build overflows with `No space left on device`.

* Give the host **at least \~15 GB free disk** when building from source.
* This only affects building the image yourself — the prebuilt Docker Hub
  images (`chattermate/backend`, `chattermate/frontend`) avoid it entirely.
* Slow-link download timeouts are already handled in the Dockerfiles
  (`PIP_DEFAULT_TIMEOUT=120` and `pip --retries 10`).

6. Help Center custom domain stuck on "SSL Provisioning" / returns 404:

The domain never reached the edge, so no certificate was issued.

* Deploy with the `chattermate-deploy` CLI **and a domain** (see
  [Help Center custom domains](#help-center-custom-domains-self-hosted)) — a plain
  localhost deploy has no TLS edge and can't serve custom domains.
* Check the domain resolves to your server (`CNAME` to your app domain) and that
  ports **80 and 443** are open — Let's Encrypt validates over both.
* The certificate is issued on the first HTTPS request; give it a few seconds,
  then re-check `Verify`. Inspect the edge with `docker compose logs caddy`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.