Running Self-Hosted Supabase in Docker Compose: RAM Sizing, Kong TLS & Pooler Config
Deploy self-hosted Supabase with Docker Compose on a 4GB or 8GB RAM server. Tune Kong API Gateway, Supavisor connection pooling, Logflare/Vector memory limits, and fix OAuth PKCE empty code_verifier errors.
The official self-hosted Supabase Docker Compose stack spins up 12+ containers (`db`, `kong`, `auth`, `rest`, `realtime`, `storage`, `imgproxy`, `meta`, `functions`, `analytics/logflare`, `vector`, and `supavisor`). Untuned, `supabase-analytics` (Elixir/Beam + BigQuery/Postgres Logflare) and `kong` consume 2.8 GB+ of idle RAM, causing OOM crashes on 2 GB or 4 GB VPS instances. By capping Kong worker processes (`KONG_NGINX_WORKER_PROCESSES=1`), disabling or memory-limiting the optional `analytics` and `vector` log-shipping containers for small-to-medium apps, and tuning PostgreSQL `shared_buffers=512MB`, the entire core Supabase stack runs smoothly in ~1.65 GB of RAM on a 4 GB container host.
Verified Root Causes in Production Environments
- Unbounded Elixir BEAM VM Memory in supabase-analytics (Logflare): The `analytics` container alone consumes 900 MB to 1.4 GB of idle RSS memory even when zero users are querying logs.
- Kong API Gateway Spawning Workers for Every Physical Host Core: Setting `KONG_NGINX_WORKER_PROCESSES=auto` on a shared cloud node spawns 8–16 Nginx worker processes inside Kong, each allocating separate Lua VM heaps.
- PKCE OAuth Empty code_verifier Behind Reverse Proxies: Misconfigured `SITE_URL`, `API_EXTERNAL_URL`, or missing `@supabase/ssr` cookie handlers cause Google/GitHub OAuth callbacks to fail on `/auth/v1/token?grant_type=pkce`.
1. Container-by-Container RAM Breakdown & 4GB VPS Tuning Strategy
While enterprise multi-SaaS guides recommend 16 GB of RAM for running a full self-hosted suite alongside ClickHouse, an individual startup or developer deploying Supabase on Vexlo Cloud or a 4 GB Ubuntu VPS does not need 1.4 GB of RAM tied up in Logflare (`supabase-analytics`) and `vector`. Core application functionality—PostgreSQL 15/16 (`db`), GoTrue (`auth`), PostgREST (`rest`), Elixir Realtime (`realtime`), Storage API (`storage`), Studio UI (`studio`), and Kong (`kong`)—requires only 1.5 GB to 1.8 GB of RAM when properly constrained.
Add the following `docker-compose.override.yml` alongside the official Supabase `docker-compose.yml` to pin Kong to 1 worker process (`KONG_NGINX_WORKER_PROCESSES=1`), cap BEAM VM memory on `realtime` and `supavisor`, and keep total stack memory under 2.2 GB.
# Place alongside Supabase's official docker-compose.yml to run comfortably on a 4GB RAM VPS
services:
kong:
environment:
KONG_NGINX_WORKER_PROCESSES: "1"
KONG_MEM_CACHE_SIZE: "32m"
deploy:
resources:
limits:
memory: 384M
db:
command:
- postgres
- -c
- config_file=/etc/postgresql/postgresql.conf
- -c
- shared_buffers=512MB
- -c
- work_mem=8MB
- -c
- max_connections=100
deploy:
resources:
limits:
memory: 1280M
realtime:
environment:
ERL_MAX_PORTS: "2048"
deploy:
resources:
limits:
memory: 384M
# Optional: Cap or disable Logflare analytics if using external Uptime Kuma / Loki logs
analytics:
deploy:
resources:
limits:
memory: 512M2. Generating Secure JWT_SECRET, ANON_KEY, and SERVICE_ROLE_KEY Tokens
Never go live with the default demo `JWT_SECRET`, `ANON_KEY`, and `SERVICE_ROLE_KEY` shipped in Supabase's `.env.example`—those exact strings are publicly indexed across GitHub, allowing anyone to bypass Row-Level Security (RLS) on your server using the default `SERVICE_ROLE_KEY`.
Generate a fresh 40+ character `JWT_SECRET` and sign matching `anon` and `service_role` JWTs (valid for 10 years) directly in Node.js before starting the stack.
import crypto from 'crypto';
const jwtSecret = crypto.randomBytes(32).toString('hex');
function signSupabaseJwt(role) {
const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64url');
const now = Math.floor(Date.now() / 1000);
const payload = Buffer.from(
JSON.stringify({
role,
iss: 'supabase',
iat: now,
exp: now + 60 * 60 * 24 * 365 * 10, // 10 years
})
).toString('base64url');
const signature = crypto
.createHmac('sha256', jwtSecret)
.update(`${header}.${payload}`)
.digest('base64url');
return `${header}.${payload}.${signature}`;
}
console.log(`JWT_SECRET=${jwtSecret}`);
console.log(`ANON_KEY=${signSupabaseJwt('anon')}`);
console.log(`SERVICE_ROLE_KEY=${signSupabaseJwt('service_role')}`);3. Fixing OAuth PKCE Empty code_verifier in Next.js + Self-Hosted Supabase
As documented in GitHub `supabase/auth` issue #2099, self-hosted Supabase OAuth flows (Google/GitHub login) fail with `empty code_verifier` when `API_EXTERNAL_URL` and `SITE_URL` in `.env` do not match your public HTTPS domain, or when redirecting directly to a client page instead of a server-side `@supabase/ssr` route handler (`/auth/callback/route.ts`) that reads the PKCE verifier cookie.
# Must match your public HTTPS domain (never leave as http://localhost:8000 in prod)
SITE_URL=https://app.vexlo.cloud
API_EXTERNAL_URL=https://supabase.vexlo.cloud
SUPABASE_PUBLIC_URL=https://supabase.vexlo.cloud
ADDITIONAL_REDIRECT_URLS=https://app.vexlo.cloud/auth/callback,http://localhost:3000/auth/callbackPre-Deployment Verification Checklist
- Replace `JWT_SECRET`, `ANON_KEY`, `SERVICE_ROLE_KEY`, `POSTGRES_PASSWORD`, and `DASHBOARD_PASSWORD` in `.env` before first boot.
- Set `KONG_NGINX_WORKER_PROCESSES=1` to save 400–700 MB of idle RAM on multi-core VPS hosts.
- Bind PostgreSQL port 5432 and Supavisor port 6543 to `127.0.0.1` or internal Docker networks so databases are not exposed to public port scanners.
- Set `API_EXTERNAL_URL` and `SUPABASE_PUBLIC_URL` to your HTTPS reverse-proxy domain so GoTrue OAuth callbacks succeed.
Deploy on Vexlo Cloud in 60s (₹149/mo UPI)
Automated Docker & Nixpacks builds, managed PostgreSQL/Redis, and AI Deployment Doctor. Instant INR UPI for India or USD/EUR/GBP across 17 global currencies.
Frequently Asked Questions
What is the actual minimum RAM required to self-host Supabase with Docker Compose?
With `KONG_NGINX_WORKER_PROCESSES=1` and memory limits applied via `docker-compose.override.yml`, the full Supabase stack runs reliably on a 4 GB RAM VPS (with 4 GB swap). For heavy Logflare analytics and high-concurrency production workloads, 8 GB to 16 GB RAM is recommended.
Can I turn off the supabase-analytics and vector containers if I don't need Logflare?
Yes. If you only need PostgreSQL, Auth, PostgREST, Realtime, Storage, and Studio Dashboard, you can comment out `analytics` and `vector` (and remove `depends_on: analytics` from other services) to immediately reclaim ~1.2 GB of RAM.
How do I secure the self-hosted Supabase Studio dashboard?
Never expose port 3000 or 8000 directly over plain HTTP. Route Kong (`8000`) behind Traefik or Caddy with HTTPS, change `DASHBOARD_USERNAME` and `DASHBOARD_PASSWORD` in `.env`, or add Traefik BasicAuth / Cloudflare Zero Trust middleware in front of `/project/default`.