This repository contains a Docker-based setup for self-hosting Supabase, an open-source Firebase alternative. Supabase provides a suite of tools and services for building modern applications including:
- PostgreSQL Database: A powerful, open-source relational database
- Authentication: User management and authentication system
- Auto-generated APIs: Instant RESTful and GraphQL APIs
- Realtime Subscriptions: Live data updates via WebSockets
- Storage: File storage and management
- Edge Functions: Serverless functions for custom logic
- Data Ownership: Complete control over your data and infrastructure
- Privacy: Keep sensitive data within your own environment
- Customization: Tailor the setup to your specific needs
- Cost Control: Manage your own infrastructure costs
- No Vendor Lock-in: Freedom to modify and extend as needed
- Docker and Docker Compose installed on your system
- Basic understanding of Docker containers and networking
- Minimum system requirements:
- 2 CPU cores
- 4GB RAM
- 20GB storage space
-
Clone this repository:
git clone <repository-url> cd supabase-starter
-
Navigate to the Supabase Docker directory:
cd Supabase-Docker -
Configure your environment variables:
cp .env.example .env
Edit the
.envfile to update the default credentials and configuration. -
Start the Supabase services:
docker compose up -d
-
Access the Supabase Studio dashboard:
http://localhost:8000Login with the credentials specified in your
.envfile (default: username:supabase, password: checkDASHBOARD_PASSWORDin your.envfile).
-
Security Credentials:
POSTGRES_PASSWORD: PostgreSQL database passwordJWT_SECRET: Secret key for JWT token generationANON_KEYandSERVICE_ROLE_KEY: API access keysDASHBOARD_USERNAMEandDASHBOARD_PASSWORD: Studio dashboard login credentials
-
Database Configuration:
POSTGRES_HOST: Database host (default:db)POSTGRES_DB: Database name (default:postgres)POSTGRES_PORT: Database port (default:5432)
-
API and Services:
KONG_HTTP_PORT: HTTP port for the API gateway (default:8000)KONG_HTTPS_PORT: HTTPS port for the API gateway (default:8443)SITE_URL: Your application's URL (default:http://localhost:3000)
To enable email authentication and notifications:
-
Update the SMTP settings in your
.envfile:ENABLE_EMAIL_SIGNUP=true SMTP_ADMIN_EMAIL=your-email@example.com SMTP_HOST=your-smtp-host SMTP_PORT=587 SMTP_USER=your-smtp-username SMTP_PASS=your-smtp-password SMTP_SENDER_NAME=Your App Name -
Customize email templates by setting the template URLs:
GOTRUE_MAILER_TEMPLATES_INVITE=https://your-template-url/invite.html GOTRUE_MAILER_TEMPLATES_CONFIRMATION=https://your-template-url/confirmation.html GOTRUE_MAILER_TEMPLATES_RECOVERY=https://your-template-url/recovery.html GOTRUE_MAILER_TEMPLATES_MAGIC_LINK=https://your-template-url/magic_link.html
/Supabase-Docker: Main directory containing Docker configurationdocker-compose.yml: Docker Compose configuration file.env: Environment variables configuration/volumes: Persistent data storage/api: API gateway configuration/db: PostgreSQL database files and initialization scripts/functions: Edge functions/logs: Log files/pooler: Database connection pooler/storage: File storage
-
Start all services:
docker compose up -d
-
Stop all services:
docker compose down
-
View logs:
docker compose logs -f
- Supabase Studio:
http://localhost:8000 - REST API:
http://localhost:8000/rest/v1/ - GraphQL API:
http://localhost:8000/graphql/v1/ - Authentication API:
http://localhost:8000/auth/v1/ - Storage API:
http://localhost:8000/storage/v1/
Use the following configuration in your client applications:
import { createClient } from "@supabase/supabase-js";
const supabaseUrl = "http://localhost:8000";
const supabaseKey = "your-anon-key"; // Find this in your .env file
const supabase = createClient(supabaseUrl, supabaseKey);-
Services not starting: Check Docker logs for specific error messages
docker compose logs [service-name]
-
Database connection issues: Verify PostgreSQL is running and accessible
docker compose exec db psql -U postgres -c "\l"
-
API errors: Check Kong gateway logs
docker compose logs kong
To update to the latest version of Supabase:
- Pull the latest changes from the repository
- Update the Docker images:
docker compose pull
- Restart the services:
docker compose down docker compose up -d
- Always change default passwords in the
.envfile - Use strong, unique passwords for all services
- Consider using a reverse proxy with SSL for production deployments
- Regularly update Docker images to get security patches
- Backup your database regularly
Supabase is licensed under the Apache 2.0 License. See the LICENSE file for details.
To connect your local Supabase instance to a self-hosted production environment, follow these steps:
-
Configure Supabase Client in Next.js: Update your Supabase client configuration in your Next.js application to point to your production URL and use the appropriate API keys.
import { createClient } from "@supabase/supabase-js"; const supabaseUrl = "https://your-production-url.com"; const supabaseKey = "your-production-anon-key"; // Ensure this key is set in your production environment const supabase = createClient(supabaseUrl, supabaseKey);
-
Environment Variables: Ensure that your production environment variables are set correctly in your hosting platform or server. This includes setting the
SUPABASE_URLandSUPABASE_KEY. -
Deploying Next.js Application: Deploy your Next.js application to your preferred hosting provider, ensuring that the environment variables are configured to connect to your self-hosted Supabase instance.
-
Testing: After deployment, test your application to ensure that it connects successfully to the Supabase instance and that all functionalities work as expected.
By following these steps, you can seamlessly integrate your local Supabase setup with a self-hosted production environment, ensuring a smooth transition from development to production.