Supabase Self-Hosting with Docker Compose
Supabase is an incredible open-source Firebase alternative. While their cloud offering is excellent, you can also self-host the entire stack using Docker Compose. This is perfect for local development, air-gapped environments, or keeping full control over your data.
Prerequisites
- Docker and Docker Compose installed (see our installation guide).
- Git installed.
Step 1: Clone the Supabase Repo
Supabase provides a pre-configured Docker setup in their official repository.
# Get the code
git clone --depth 1 https://github.com/supabase/supabase
cd supabase/docker
Step 2: Configure Environment Variables
Copy the example environment file:
cp .env.example .env
Now, open .env in your text editor. This file controls everything.
Key Variables to Change
POSTGRES_PASSWORD: The password for thepostgresuser. Change this immediately if deploying to a public server.JWT_SECRET: Used to sign authentication tokens. Generate a strong, random string.ANON_KEYandSERVICE_ROLE_KEY: These are JWTs derived from yourJWT_SECRET. You must generate new ones if you change the secret. You can use the Supabase CLI or an online JWT tool to generate these (ensure you use the correct payload structure).DASHBOARD_USERNAME/DASHBOARD_PASSWORD: Credentials for the Supabase Studio UI.
Step 3: Start the Stack
Run Docker Compose to pull the images and start the services.
docker compose pull
docker compose up -d
This will start a suite of services:
- Postgres: The core database.
- GoTrue: Authentication API.
- PostgREST: Auto-generated REST API.
- Realtime: WebSocket server.
- Storage: File storage API.
- Studio: The dashboard UI.
- Kong: API Gateway.
Step 4: Accessing Supabase
Once everything is running (check with docker compose ps), you can access the services:
- Supabase Studio (UI):
http://localhost:3000(Default login:supabase/this_password_is_insecure_and_should_be_updated) - API Gateway:
http://localhost:8000 - Postgres Database:
localhost:5432
Enabling Analytics (Optional)
The default setup might not include the analytics container (Logflare) enabled by default to save resources. Check the docker-compose.yml file and uncomment the analytics services if you need them.
Data Persistence
The docker-compose.yml uses named volumes to persist data.
db-data: Postgres data.storage-data: File uploads.
If you restart the containers, your data remains safe. To wipe everything and start fresh:
docker compose down -v