Skip to content

Docker Setup

This guide walks you through deploying Supatype on a server using Docker Compose. The CLI renders the Compose file from your project’s supatype.config.ts and runs it for you, so the server holds a checkout of your project rather than a hand-maintained stack.

Prerequisites

  • A server with Docker 20.10+ and Docker Compose v2
  • Node.js 18 or later for the Supatype CLI, or 20.19 or later if the server builds a Vite 8 frontend
  • A domain name (optional but recommended for production)

Step 1: Get the project onto the server

Install the CLI and clone your project (or create one with supatype init):

Terminal window
npm install -g @supatype/cli
git clone git@github.com:YOUR_USER/my-app.git /opt/my-app
cd /opt/my-app
npm install

Render the Compose stack:

Terminal window
supatype self-host compose render

This writes the generated files under .supatype/self-host/:

.supatype/self-host/
├── docker-compose.yml
├── kong.yml
└── s3.json

Do not edit them by hand: every self-host compose command writes them again from your config before it runs. Database, storage and cache data live in Docker volumes, not in this directory.

docker-compose.yml names every bind mount by its absolute path on this machine and names its Compose project (supatype- plus project.name), so a docker compose command run against it by hand reaches the same stack with the same files. If you move the project to another folder, the next self-host compose command writes the new paths.

Step 2: Configure environment

Create .env in the project root on the server and never commit it. supatype init generates one with fresh secrets; on a server, use new values of your own:

Terminal window
# Database
DATABASE_URL=postgresql://supatype_admin:CHANGE_ME@localhost:5432/my-app
POSTGRES_USER=supatype_admin
POSTGRES_PASSWORD=CHANGE_ME
POSTGRES_DB=my-app
AUTHENTICATOR_PASSWORD=a-different-long-random-string
SUPATYPE_SQL_EDITOR_PASSWORD=a-third-long-random-string
# JWT: the API keys are derived from this secret
JWT_SECRET=your-super-secret-jwt-key-at-least-32-characters
ANON_KEY=
SERVICE_ROLE_KEY=
# Public URLs
API_EXTERNAL_URL=https://api.your-domain.com
SITE_URL=https://your-domain.com

Email delivery is not set here. supatype self-host compose writes the mailer settings into .env from the email block of supatype.config.ts, so a provider typed into .env by hand is put back to the config’s value (console when the config has no email) the next time you run it, and the CLI prints a warning naming the key. Set it in the config instead:

supatype.config.ts
email: {
provider: "smtp",
smtp: {
host: "smtp.sendgrid.net",
port: 587,
user: "apikey",
pass: process.env.SMTP_PASS,
admin_email: "noreply@your-domain.com",
},
},

See Configuration for every key.

Generate the API keys from JWT_SECRET and write them into .env:

Terminal window
supatype keys --write

supatype self-host compose up also fills in blank keys on its own, and every self-host compose command adds SUPATYPE_CONTROL_PLANE_SECRET when it is missing. When the cache runs inside Postgres on supatype/postgres 17.2.13 or later, it adds SUPATYPE_KEYSPACE_PASSWORD, the cache’s password, the same way (Cache). The three passwords are required: Compose stops before starting anything and names the one that is missing. See Configuration for every variable the stack reads.

JWT_SECRET must be at least 32 characters, because PostgREST will not start with a shorter one. supatype self-host compose up checks it first and stops with JWT_SECRET in .env is <n> characters, and the REST API needs at least 32. Generate one with openssl rand -base64 48, then run supatype keys --write --force to sign new keys with it.

To configure OAuth sign-in, list the providers under auth.providers in supatype.config.ts and put their secrets in .env; render and up warn about an enabled provider whose secret is set nowhere. See OAuth providers.

Step 3: Start the services

Terminal window
supatype self-host compose up -d
supatype push

push applies your schema to the new database. Until the first push, every /rest/v1/ request answers 503 with PGRST002: PostgREST will not serve until the schemas it exposes exist. That is expected, not a fault. After the push PostgREST can take about 30 seconds to notice, so push waits (at most 40 seconds, printing one line) until REST stops answering 503. If it gives up, the schema is still applied, and supatype self-host compose logs --service postgrest shows why REST is not serving.

Then check the services:

Terminal window
supatype self-host compose status

The stack runs db, postgrest, server (the API gateway service, including auth), storage, seaweedfs (the object store behind storage, left out when storage.production is "s3", see Configuration), functions-worker, control-plane, studio and kong, plus realtime unless realtime is turned off, and valkey if you chose cache: { provider: "valkey" } or use an external database. The file also declares schema-engine, which does not stay running: a push runs it once and it exits.

Kong publishes the API on port 18473 (SUPATYPE_KONG_PORT in .env changes it), with Studio at /studio/: open http://YOUR_SERVER_IP:18473/studio/.

Step 4: Set up HTTPS

The stack can serve HTTPS itself. Set a domain and an ACME email in supatype.config.ts, and Kong publishes ports 80 and 443 and obtains a Let’s Encrypt certificate:

// supatype.config.ts (excerpt)
server: {
mode: "standalone",
domain: "api.your-domain.com",
tls: { email: "you@your-domain.com" },
},

Then run supatype self-host compose up -d again.

Or keep HTTP on 18473 and put your own reverse proxy in front. Here is an example with Caddy:

# Caddyfile
api.your-domain.com {
reverse_proxy localhost:18473
}

Or with nginx:

server {
listen 443 ssl;
server_name api.your-domain.com;
ssl_certificate /etc/letsencrypt/live/api.your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.your-domain.com/privkey.pem;
location / {
proxy_pass http://localhost:18473;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

Studio is served by the same gateway, at https://api.your-domain.com/studio/; it needs no domain of its own.

Step 5: Connect your project

Link your local Supatype project to the self-hosted instance:

Terminal window
# In your project directory
supatype link --url https://api.your-domain.com --token <SERVICE_ROLE_KEY>

Step 6: Serve your frontend

To have the stack serve a static app, record where its build goes, once, and commit supatype.config.ts:

Terminal window
supatype app add --static ./dist

Then build it on the server with supatype build rather than npm run build, and start the stack:

Terminal window
supatype build
supatype self-host compose up -d

supatype build runs the package.json build script with the deployment’s API URL and anon key under every framework’s name (VITE_, PUBLIC_, NEXT_PUBLIC_, EXPO_PUBLIC_). On the server it reads them from .env: API_EXTERNAL_URL (or PUBLIC_SUPATYPE_URL) and ANON_KEY. When either is missing, or API_EXTERNAL_URL is still a localhost address, it stops before the build starts and lists every source it tried, instead of building a site that renders a blank page.

The server also answers /supatype-env.js with its own address and anon key. An index.html that loads it with <script src="/supatype-env.js" vite-ignore></script> (supatype init adds the tag for a static app; vite-ignore stops vite build warning that the file does not exist) gets both values when the page loads, so one build runs on every deployment that serves it. For an API-only project, set server.public_env: false in supatype.config.ts to turn that address off; the anon key is public either way. Building on Vercel, Netlify, Cloudflare Pages or in CI is covered in Deploy your frontend.

Step 7: Deploy on every push

A GitHub Action can SSH in and run the same commands you ran by hand:

name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
key: ${{ secrets.VM_SSH_KEY }}
script: |
cd ${{ secrets.DEPLOY_PATH }}
git pull
npm install
supatype self-host compose up -d
supatype push
supatype build
supatype self-host compose up -d

The second compose up -d picks up the new build. For a project with no frontend, leave out the last two lines.

The repository secrets it needs:

  • VM_HOST: public IP or hostname of the server
  • VM_USER: SSH user
  • VM_SSH_KEY: a private key that can log in as VM_USER
  • DEPLOY_PATH: the project checkout on the server, such as /opt/my-app

.env stays on the server and out of the repository, so git pull never touches it.

Backups

The database is published on the host at port 5432 (SUPATYPE_DB_PORT changes it), so a nightly pg_dump on the server can read DATABASE_URL from the project’s .env. The port is bound to 127.0.0.1 only, unless SUPATYPE_PUBLISH_ADDRESS in .env names another address; if you set one, keep the port closed in your firewall.

Terminal window
# Add to crontab
0 2 * * * cd /opt/my-app && set -a && . ./.env && pg_dump "$DATABASE_URL" | gzip > /backups/supatype-$(date +\%Y\%m\%d).sql.gz

Updating

Upgrade the CLI first when supatype update says a newer release exists, because the image pins come from the CLI version (supatype update --check shows the running and latest versions without pulling). Then pull the images, restart the stack, and apply any schema changes the new versions expect:

Terminal window
supatype update
supatype self-host compose up -d
supatype push

The push is the step people miss. The images ship code, but grants, policies, functions and buckets are generated from your schema and reach the database only through push, so treat an upgrade as finished only after it runs.

Commands that render the Compose file keep the stack in the mode its server container is running in, so push, diff, adopt and update against a production stack leave it standalone and leave .env alone. Dev mode is used only while a supatype dev session for the project is running.

Restarting one service

After changing .env or supatype.config.ts, recreate the service it affects and leave the rest running:

Terminal window
supatype self-host compose restart server
supatype self-host compose restart functions-worker # after editing functions/

This renders the file again and recreates the container, so the change reaches it. Compose’s own docker compose restart keeps the container as it was created, so it would not pick up a changed .env.

Troubleshooting

Check service logs:

Terminal window
supatype self-host compose logs --service postgrest # PostgREST logs
supatype self-host compose logs --service server # API server and auth logs
supatype self-host compose logs --service db # PostgreSQL logs

Stop the stack (data is kept):

Terminal window
supatype self-host compose down

Reset the stack (destroys all data). --volumes removes the database and every stored file, and asks first; --yes skips the question:

Terminal window
supatype self-host compose down --volumes
supatype self-host compose up -d
supatype push