LOCAL SUPABASE SETUP
Local Supabase Development Setup
Section titled “Local Supabase Development Setup”This guide walks you through setting up a local Supabase instance for development using Docker Compose.
Table of Contents
Section titled “Table of Contents”- Overview
- Prerequisites
- Quick Start
- Configuration
- Available Commands
- Working with Migrations
- Troubleshooting
- Architecture
Overview
Section titled “Overview”Running Supabase locally provides several benefits:
- Offline Development: Work without internet connection
- Cost Savings: No API calls to production during development
- Data Isolation: Test destructive operations safely
- Faster Iteration: No network latency
- Reproducible Environment: Consistent setup across team
Prerequisites
Section titled “Prerequisites”Before starting, ensure you have:
- Docker (v20.10+) and Docker Compose (v2.0+)
- Make (for convenient commands)
- At least 4GB RAM available for Docker
- Ports available:
54321(API),54323(Studio),5432(Database)
Check Prerequisites
Section titled “Check Prerequisites”docker --version # Should be 20.10+docker-compose --version # Should be 2.0+make --version # Any recent versionQuick Start
Section titled “Quick Start”1. Initial Setup
Section titled “1. Initial Setup”# Copy the environment templatecp .env.local .env.local.custom
# Edit .env.local.custom and update these critical values:# - POSTGRES_PASSWORD# - JWT_SECRET# - ANON_KEY and SERVICE_ROLE_KEY (generate at https://supabase.com/docs/guides/self-hosting)2. Start Supabase
Section titled “2. Start Supabase”# Start all Supabase servicesmake supabase-start
# This will start:# - PostgreSQL database# - PostgREST API# - GoTrue authentication# - Realtime server# - Storage server# - Studio dashboard3. Access Services
Section titled “3. Access Services”Once started, you can access:
- Supabase Studio: http://localhost:54323
- API Endpoint: http://localhost:54321
- Database:
postgresql://postgres:your-password@localhost:5432/postgres
4. Apply Migrations
Section titled “4. Apply Migrations”# Run all migrations to set up your schemamake supabase-migrate5. Configure Your App
Section titled “5. Configure Your App”Update your local environment variables in packages/webapp/.env:
VITE_SUPABASE_URL=http://localhost:54321VITE_SUPABASE_ANON_KEY=your-anon-key-from-env-local6. Start Development
Section titled “6. Start Development”# In one terminal: keep Supabase runningmake supabase-logs
# In another terminal: start your appmake test-watch
# In a third terminal: start the dev servermake devConfiguration
Section titled “Configuration”Environment Variables
Section titled “Environment Variables”The .env.local file contains all configuration for local Supabase. Key variables:
Database Configuration
Section titled “Database Configuration”POSTGRES_PASSWORD=your-super-secret-and-long-postgres-passwordPOSTGRES_DB=postgresPOSTGRES_PORT=5432API Configuration
Section titled “API Configuration”API_EXTERNAL_URL=http://localhost:54321SUPABASE_PUBLIC_URL=http://localhost:54321JWT Configuration
Section titled “JWT Configuration”JWT_SECRET=your-super-secret-jwt-token-with-at-least-32-characters-longJWT_EXPIRY=3600ANON_KEY=your-anon-keySERVICE_ROLE_KEY=your-service-role-keyAuth Configuration
Section titled “Auth Configuration”SITE_URL=http://localhost:5173DISABLE_SIGNUP=falseENABLE_EMAIL_SIGNUP=trueMAILER_AUTOCONFIRM=true # Auto-confirm emails in devGenerating JWT Keys
Section titled “Generating JWT Keys”To generate proper ANON_KEY and SERVICE_ROLE_KEY:
- Visit https://supabase.com/docs/guides/self-hosting/docker#generate-api-keys
- Use your
JWT_SECRETto generate keys - Or use the default development keys (not for production!)
Available Commands
Section titled “Available Commands”Service Management
Section titled “Service Management”make supabase-start # Start all servicesmake supabase-stop # Stop all servicesmake supabase-restart # Restart all servicesmake supabase-status # Check service statusmake supabase-logs # View service logs (follow mode)Database Operations
Section titled “Database Operations”make supabase-db # Connect to database CLImake supabase-migrate # Run migrationsmake supabase-seed # Seed test datamake supabase-backup # Backup databasemake supabase-restore FILE=backup.sql # Restore from backupDevelopment Tools
Section titled “Development Tools”make supabase-studio # Open Studio in browsermake supabase-reset # Reset database (WARNING: deletes data)make supabase-clean # Clean up Docker resourcesWorking with Migrations
Section titled “Working with Migrations”Applying Migrations
Section titled “Applying Migrations”All migrations in supabase/migrations/ are automatically detected:
make supabase-migrateThis runs migrations in alphanumeric order.
Creating Migrations
Section titled “Creating Migrations”- Using Studio: Make schema changes in Studio (http://localhost:54323)
- Generate SQL: Studio can generate migration SQL
- Save Migration: Create file in
supabase/migrations/:Terminal window # Format: YYYYMMDD_description.sqltouch supabase/migrations/$(date +%Y%m%d)_add_new_table.sql - Apply Migration: Run
make supabase-migrate
Migration Best Practices
Section titled “Migration Best Practices”- One Change Per Migration: Makes rollback easier
- Descriptive Names:
20250102_add_user_profiles_table.sql - Idempotent SQL: Use
IF NOT EXISTSclauses - Test Locally First: Always test on local before production
Example migration:
-- supabase/migrations/20250102_add_notifications_table.sqlCREATE TABLE IF NOT EXISTS notifications ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID REFERENCES auth.users(id), message TEXT NOT NULL, read BOOLEAN DEFAULT false, created_at TIMESTAMPTZ DEFAULT NOW());
-- Enable RLSALTER TABLE notifications ENABLE ROW LEVEL SECURITY;
-- Create policiesCREATE POLICY "Users can view own notifications" ON notifications FOR SELECT USING (auth.uid() = user_id);Troubleshooting
Section titled “Troubleshooting”Services Won’t Start
Section titled “Services Won’t Start”Problem: Docker services fail to start
Solutions:
# Check if ports are already in uselsof -i :54321 # API portlsof -i :54323 # Studio portlsof -i :5432 # Database port
# Stop conflicting services or change ports in .env.local
# Check Docker resourcesdocker system dfdocker system prune -f # Clean up unused resourcesDatabase Connection Errors
Section titled “Database Connection Errors”Problem: Can’t connect to database
Solutions:
# Check database is runningmake supabase-status
# View database logsdocker-compose logs db
# Restart database servicedocker-compose restart dbStudio Not Loading
Section titled “Studio Not Loading”Problem: Studio shows white screen or errors
Solutions:
# Check Studio logsdocker-compose logs studio
# Verify Studio dependencies are healthydocker-compose ps
# Restart Studiodocker-compose restart studioMigrations Failing
Section titled “Migrations Failing”Problem: Migration script fails to apply
Solutions:
# Apply migrations one by one to find the issuefor file in supabase/migrations/*.sql; do echo "Applying: $file" docker-compose exec -T db psql -U postgres -f - < "$file" || breakdone
# Connect to DB and check manuallymake supabase-db
# Check for syntax errors in migration files# Use a SQL linter or Studio's SQL editorPerformance Issues
Section titled “Performance Issues”Problem: Slow queries or timeouts
Solutions:
# Increase Docker resources in Docker Desktop settings# Recommended: 4GB RAM minimum, 8GB preferred
# Check container resource usagedocker stats
# Reset and optimizemake supabase-resetmake supabase-migratePort Conflicts
Section titled “Port Conflicts”Problem: Port already in use
Solutions:
# Option 1: Stop conflicting servicesudo lsof -ti:54321 | xargs kill -9
# Option 2: Change ports in .env.localKONG_HTTP_PORT=44321STUDIO_PORT=44323POSTGRES_PORT=44322Architecture
Section titled “Architecture”Service Overview
Section titled “Service Overview”Local Supabase consists of multiple services:
┌─────────────────────────────────────────────┐│ Supabase Studio (54323) ││ Admin Dashboard & GUI │└─────────────────────────────────────────────┘ │┌─────────────────────────────────────────────┐│ Kong Gateway (54321) ││ API Gateway & Routing │└─────────────────────────────────────────────┘ │ │ │ ┌──────┴───┐ ┌──┴────┐ ┌─┴──────┐ │ │ │ │ │ │┌───▼───┐ ┌──▼──┐ ┌──▼──┐ ┌────▼────┐│ REST │ │Auth │ │Real │ │ Storage ││PostgRE│ │GoTru│ │time │ │ API ││ ST │ │ e │ │ │ │ │└───┬───┘ └──┬──┘ └──┬──┘ └────┬────┘ │ │ │ │ └─────────┴────────┴──────────┘ │ ┌──────────▼──────────┐ │ PostgreSQL (5432) │ │ Database + pgvecto│ └─────────────────────┘Service Descriptions
Section titled “Service Descriptions”- PostgreSQL: Core database with Supabase extensions
- PostgREST: Auto-generates REST API from database schema
- GoTrue: Handles authentication and user management
- Realtime: WebSocket server for live data subscriptions
- Storage: Object storage for files and media
- Kong: API gateway for routing and authentication
- Studio: Web-based admin dashboard
- Analytics: Log aggregation with Logflare
- Vector: Log routing and transformation
Data Persistence
Section titled “Data Persistence”Local data is stored in Docker volumes:
docker/volumes/├── db/data/ # PostgreSQL data files├── storage/ # Uploaded files and objects├── api/ # Kong configuration└── logs/ # Application logsNetworking
Section titled “Networking”All services communicate on the supabase-network Docker network:
- Services use internal hostnames (e.g.,
db,rest,auth) - External access through exposed ports only
- Kong routes external requests to internal services
Production Differences
Section titled “Production Differences”Local development differs from production Supabase:
| Aspect | Local | Production |
|---|---|---|
| Auto-confirm emails | ✅ Enabled | ❌ Disabled |
| HTTPS | ❌ HTTP only | ✅ Required |
| Email delivery | 🔧 Mock/Local | ✉️ Real SMTP |
| Backups | 🔧 Manual | ☁️ Automated |
| Resources | 💻 Limited by Docker | ☁️ Scalable |
| Monitoring | 📊 Basic logs | 📈 Full observability |
Next Steps
Section titled “Next Steps”Additional Resources
Section titled “Additional Resources”- Official Supabase Self-Hosting Guide
- Supabase GitHub Repository
- Docker Compose Documentation
- PostgreSQL Documentation
Support
Section titled “Support”For issues with local Supabase setup:
- Check Troubleshooting section above
- Review Supabase Discord
- Open an issue in the project repository
- Check Docker logs:
make supabase-logs