# Docker

> Run the engine as a container with Postgres and a mail catcher, for development or production.

Applies to: the Sypnia engine (open source, self-hosted).  
Source: https://data.docs.sypnia.com/self-hosting/docker/

For agents: Docker: image ghcr.io/sespinosav/sypnia-data:<version> (linux/amd64 and linux/arm64, distroless, non-root, port 8080, healthcheck `sypnia-data health`). The repository's docker-compose.yml runs Postgres 16, the engine and Mailpit (e-mails at http://localhost:8025); copy .env.example to .env and set SYPNIA_DATA_MASTER_KEY (openssl rand -base64 32) and POSTGRES_PASSWORD. SYPNIA_DATA_INSTALL_ON_START=true installs or upgrades the schema before serving (waits for the database). Keys: `docker compose exec data sypnia-data keys api-key --kind publishable|secret`. Users: `docker compose exec -e SYPNIA_DATA_NEW_PASSWORD=… data sypnia-data users create <email>`. MCP at <public URL>/mcp. SYPNIA_DATA_TICK=internal for e-mail retries and cleanup. Put TLS in front and forward Host.

The repository has a `docker-compose.yml` that runs everything on one machine: **Postgres 16**, **the engine** and **Mailpit**, which catches every e-mail so you can read sign-up and password links locally.

## Start

```bash
git clone https://github.com/sespinosav/sypnia-data && cd sypnia-data
cp .env.example .env
```

Fill the two secrets in `.env`, generating them on your machine:

```bash
openssl rand -base64 32   # SYPNIA_DATA_MASTER_KEY: keep it safe, without it every session ends
openssl rand -base64 24   # POSTGRES_PASSWORD
```

```bash
docker compose up -d
docker compose ps          # db, mailpit and data become healthy
curl http://localhost:8080/health
```

On its first start the engine installs its schema in the database (it waits until Postgres is ready). After an upgrade it applies the new migrations before it serves. Both come from `SYPNIA_DATA_INSTALL_ON_START=true`.

## Keys and a first user

```bash
docker compose exec data sypnia-data keys api-key --kind publishable   # for your app (browser-safe)
docker compose exec data sypnia-data keys api-key --kind secret        # for your servers; shown once
docker compose exec -e SYPNIA_DATA_NEW_PASSWORD='a long passphrase' data sypnia-data users create ana@example.com
```

Sign-ups, magic links and password resets land in Mailpit at `http://localhost:8025`.

## What runs

| Service   | Image                                                   | Port             | Notes                                                                               |
| --------- | ------------------------------------------------------- | ---------------- | ----------------------------------------------------------------------------------- |
| `db`      | `postgres:16-bookworm`                                  | inside only      | data in the `pgdata` volume                                                         |
| `mailpit` | `axllent/mailpit:v1.27`                                 | `127.0.0.1:8025` | the web UI; SMTP on `mailpit:1025` inside                                           |
| `data`    | `ghcr.io/sespinosav/sypnia-data:${SYPNIA_DATA_VERSION}` | `127.0.0.1:8080` | auth, Data API, SQL, and [MCP](https://data.docs.sypnia.com/machines/mcp) at `/mcp` |

The engine's image is distroless and runs as a non-root user. It is built for `linux/amd64` and `linux/arm64`, and its healthcheck is `sypnia-data health`. Compose caps each container's memory.

## Production

- **TLS in front.** The engine speaks plain HTTP on port 8080. Put Caddy, nginx, Traefik or your cloud's load balancer in front, and forward the `Host` header: the engine uses it to pick the project and to build links in e-mails.
- **Your address.** Set `SYPNIA_DATA_PUBLIC_URL` to the address people reach (`https://api.myapp.com`).
- **A real mail provider.** Replace Mailpit with `SYPNIA_DATA_MAIL=smtp|resend|postmark|ses` ([configuration](https://data.docs.sypnia.com/self-hosting/configuration)).
- **Pin a version.** Use `SYPNIA_DATA_VERSION=0.1.0`, never `latest`.
- **Keep the master key out of files.** In production, keep `SYPNIA_DATA_MASTER_KEY` in a secrets manager rather than in `.env`.
- **Replicas.** Two replicas behind the proxy share nothing but the database.
- **Logs.** They go to stdout as JSON lines with a request id; secrets are never logged.

Upgrading is in [Upgrades and backups](https://data.docs.sypnia.com/self-hosting/upgrades-and-backups).
