D: Self-hosting Supabase gives you full control over your PostgreSQL database, authentication, and real-time APIs. In this guide, we’ll walk through deploying Supabase using Docker and connecting it to a custom domain for API access.
π§ Prerequisites
Before starting, ensure you have:
- A Linux server (Ubuntu/Debian recommended)
- Docker & Docker Compose installed
- A domain name (e.g.,
api.yourdomain.com
) - Basic terminal skills
οΏ½ Step 1: Install Docker & Docker Compose
Run these commands to set up Docker:
# Install Docker
sudo apt update && sudo apt install docker.io
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Verify with:
docker --version && docker-compose --version
π Step 2: Deploy Supabase with Docker
Supabase provides an official docker-compose.yml
file.
-
Clone the Supabase repo:
git clone --depth 1 https://github.com/supabase/supabase cd supabase/docker
-
Edit
.env
file:
Modifydocker/.env
to set:POSTGRES_PASSWORD=YourStrongPassword123! JWT_SECRET=YourRandomJWTSecretKey SITE_URL=https://yourdomain.com
-
Start Supabase:
sudo docker-compose up -d
This launches:
- PostgreSQL (Port
5432
) - Studio (Port
3000
) - Kong API Gateway (Port
8000
)
- PostgreSQL (Port
π Step 3: Connect a Custom Domain to Supabase API
To access Supabase APIs via api.yourdomain.com
:
Option A: Using Nginx (Recommended)
-
Install Nginx:
sudo apt install nginx
-
Configure a reverse proxy:
Edit/etc/nginx/sites-available/supabase
:server { listen 80; server_name api.yourdomain.com; location / { proxy_pass http://localhost:8000; proxy_set_header Host $host; } }
-
Enable the config:
sudo ln -s /etc/nginx/sites-available/supabase /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl restart nginx
Option B: Cloudflare Proxy
If using Cloudflare:
- Set DNS
A record
forapi.yourdomain.com
β Your server IP - Enable Proxy (Orange Cloud)
π Step 4: Secure with SSL (HTTPS)
Use Letβs Encrypt for free SSL:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d api.yourdomain.com
Auto-renewal:
sudo certbot renew --dry-run
π¦ Step 5: Configure Supabase Client
Update your appβs Supabase client:
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(
'https://api.yourdomain.com',
'your-anon-key' // Get from Supabase Studio → Settings → API
)
π Troubleshooting
- Port conflicts? β Edit
docker-compose.yml
to change ports. - Database not starting? β Check logs:
docker logs supabase-db
- API Gateway issues? β Restart Kong:
docker restart supabase-kong
π Done!
You now have a self-hosted Supabase with:
β
PostgreSQL + Auth
β
Realtime APIs
β
Custom domain (api.yourdomain.com
)
β
HTTPS security
For scaling, consider adding load balancing or separate DB backups. Happy coding! π»π₯
Pro Tip: Monitor with
docker stats
and set up automated backups for your database!