When to use this stack
Supabase is a bundle of services built around Postgres: an API gateway, an authentication service, a REST layer, realtime subscriptions, file storage and a studio UI. Its self-hosted version is documented by Supabase itself and is far larger than one compose file, so copying a partial bundle from a blog post is the most common way to get a broken setup. This stack keeps the two parts that give most of the value locally: a Postgres database built from the supabase/postgres image, which includes the database roles that Supabase expects, and PostgREST, which turns tables in the public schema into a REST API that checks JWTs. The image tags are pinned to supabase/postgres 15.8.1.085 and PostgREST v16.5.
Use this reduced stack when you need a Postgres backend with an instant REST API for a prototype or an internal tool, and you are comfortable writing grants and row-level security policies yourself. Do not use it when you need sign-in, email login, file uploads or realtime updates out of the box. In that case, follow the official guide at https://supabase.com/docs/guides/self-hosting/docker, which adds Auth, Storage, Realtime, Studio and Kong, or use a hosted project. This file deliberately does not reproduce that larger setup, because the official configuration files change between releases and an inexact copy would fail in confusing ways.
docker-compose.yml
services:
db:
image: supabase/postgres:15.8.1.085
restart: unless-stopped
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 10
postgrest:
image: postgrest/postgrest:v16.5
restart: unless-stopped
depends_on:
db:
condition: service_healthy
environment:
PGRST_DB_URI: postgres://postgres:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
PGRST_DB_SCHEMAS: public
PGRST_DB_ANON_ROLE: anon
PGRST_JWT_SECRET: ${JWT_SECRET}
ports:
- "127.0.0.1:3000:3000"
volumes:
db_data:POSTGRES_PASSWORD=CHANGE_ME_DB_PASSWORD_ALPHANUMERIC
POSTGRES_DB=postgres
JWT_SECRET=CHANGE_ME_JWT_SECRET_MIN_32_CHARACTERS_LONG_xx.env
POSTGRES_PASSWORD=CHANGE_ME_DB_PASSWORD_ALPHANUMERIC
POSTGRES_DB=postgres
JWT_SECRET=CHANGE_ME_JWT_SECRET_MIN_32_CHARACTERS_LONG_xxStart and verify
# 1. Generate a JWT secret of 64 hex characters and paste it into JWT_SECRET
openssl rand -hex 32
# 2. Validate the compose file and the variable substitution
docker compose config --quiet
# 3. Start the database and PostgREST
docker compose up -d
# 4. db should show "(healthy)" and postgrest should show "Up"
docker compose ps
# 5. Confirm that the roles PostgREST depends on exist (expected: anon and authenticated)
docker compose exec db psql -U postgres -d postgres -c "SELECT rolname FROM pg_roles WHERE rolname IN ('anon', 'authenticated');"
# 6. Check the REST root with the anon role (expected: 200)
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:3000/
# 7. Read the PostgREST log if the check fails
docker compose logs --tail=50 postgrestTo test the API, create a table in the public schema, grant SELECT to anon, and request it at http://127.0.0.1:3000/your_table. Do this only with test data until you have written your policies.
Production checklist
- Keep the database port unpublished. Only PostgREST should be reachable, and only through a reverse proxy with HTTPS.
- Create a dedicated login role for PostgREST with NOINHERIT and grant it only the anon and authenticated roles, instead of connecting as the postgres superuser as this teaching file does.
- Enable row-level security on every exposed table and write policies before you grant anything to anon.
- Never give clients the service_role key or a token signed with JWT_SECRET. Anyone holding such a token bypasses your policies.
- Use a JWT secret of at least 32 random characters. Rotating it invalidates every token that is currently in use.
- Schedule backups with pg_dump and test a restore, because the volume is the only copy of the data.
- Pin both image tags and upgrade them on purpose, checking the release notes of supabase/postgres and PostgREST.
- Restrict the host firewall so that only ports 80 and 443 and your SSH port are open to the internet.
Common problems
- Symptom: PostgREST exits with password authentication failed for user postgres. Cause: POSTGRES_PASSWORD was changed after the volume was first initialized, and the volume keeps the original password. Fix: set the old password back in .env, or change the password inside the database with ALTER USER and then restart the stack.
- Symptom: requests with a valid-looking token return 401 with an invalid JWT message. Cause: the token was signed with a different secret, or PGRST_JWT_SECRET is shorter than 32 characters. Fix: sign tokens with exactly the JWT_SECRET value and use a longer secret.
- Symptom: anonymous requests return permission denied for table. Cause: the anon role has no privileges on the table. Fix: grant SELECT to anon on that table and add row-level security policies if you enable RLS.
- Symptom: the REST root is empty or your table is missing from the API. Cause: the table lives in a schema other than public, or PostgREST has not reloaded its schema cache. Fix: add the schema to PGRST_DB_SCHEMAS, or run docker compose restart postgrest after creating the table.
- Symptom: PostgREST exits saying the role anon does not exist. Cause: the database was initialized from a plain Postgres image instead of supabase/postgres. Fix: create the anon and authenticated roles yourself with CREATE ROLE, or switch back to the supabase/postgres image.
Variations
- Full Supabase stack: follow the official self-hosting guide at https://supabase.com/docs/guides/self-hosting/docker. Use it when you need Auth, Storage, Realtime or Studio. Keep the database and its volume from this stack only if the official files match your Postgres image version.
- Plain Postgres with PostgREST: use postgres:16 as the database, create the anon and authenticated roles and an authenticator role by hand, then point PGRST_DB_URI at that role. This removes the Supabase-specific image but adds manual setup.
- Caddy in front of PostgREST: add a Caddy service that proxies your domain to postgrest:3000 on the Docker network. Caddy terminates TLS, so PostgREST never needs a public port.
Questions
Is this the full Supabase stack?
No. This is a reduced stack with Postgres and PostgREST only. Authentication, storage, realtime, Studio and the Kong gateway are missing. The official self-hosting guide at https://supabase.com/docs/guides/self-hosting/docker describes the complete setup.
Why does PostgREST need a JWT secret?
PostgREST checks the signature of every JWT in the Authorization header with PGRST_JWT_SECRET, then switches to the database role named in the token. The secret must be at least 32 characters long.
Why can anonymous requests read nothing?
The anon role only has the privileges you grant it. Tables are not exposed until you grant SELECT to anon and, if row-level security is enabled, add policies for that role.
Adapt this stack
Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.
Open in builderRelated stacks
Nextcloud + MariaDB + Redis File Sync
Self-host Nextcloud with MariaDB 11.4 and Redis in Docker Compose. Pinned tags, database healthcheck, memory cache and the production steps for HTTPS and cron.
Home Assistant Smart Home Hub
Run Home Assistant 2026.10 in Docker Compose with a pinned image, persistent config volume, timezone setup and reverse proxy notes for secure remote access.
n8n Workflow Automation with PostgreSQL
Self-host n8n 2.48 with PostgreSQL 16 in Docker Compose: encrypted credentials, database healthcheck, loopback-only port and a production checklist.
Ollama + Open WebUI Local AI Chat
Run local AI models with Ollama and a chat interface with Open WebUI in Docker Compose. Pinned images, a health check, loopback-only access and RAM guidance.
Browse more Automation, AI & Self-Hosted stacks or the full library.