0
0
Supabasecloud~5 mins

Self-hosting Supabase

Choose your learning style9 modes available
Introduction

Self-hosting Supabase lets you run your own backend services. This gives you full control over your data and setup without relying on external servers.

You want to keep your data private and on your own servers.
You need to customize Supabase features beyond the hosted version.
You want to avoid monthly costs of hosted services by using your own hardware.
You have specific compliance or security rules to follow.
You want to learn how backend services work by managing them yourself.
Syntax
Supabase
docker-compose.yml

version: '3.6'
services:
  supabase-db:
    image: supabase/postgres:latest
    ports:
      - '5432:5432'
    environment:
      POSTGRES_PASSWORD: yourpassword
  supabase-api:
    image: supabase/gotrue:latest
    ports:
      - '9999:9999'
    depends_on:
      - supabase-db
    environment:
      GOTRUE_DB_DRIVER: 'postgres'
      GOTRUE_DB_DATABASE_URL: 'postgres://postgres:yourpassword@supabase-db:5432/postgres'
  supabase-realtime:
    image: supabase/realtime:latest
    ports:
      - '4000:4000'
    depends_on:
      - supabase-db
    environment:
      DB_HOST: supabase-db
      DB_PORT: 5432
      DB_USER: postgres
      DB_PASSWORD: yourpassword
      DB_NAME: postgres

This example uses Docker Compose to run Supabase services locally.

Replace yourpassword with a strong password you choose.

Examples
This starts only the database service with a password.
Supabase
version: '3.6'
services:
  supabase-db:
    image: supabase/postgres:latest
    ports:
      - '5432:5432'
    environment:
      POSTGRES_PASSWORD: examplepass
This starts the authentication API connected to the database.
Supabase
version: '3.6'
services:
  supabase-api:
    image: supabase/gotrue:latest
    ports:
      - '9999:9999'
    depends_on:
      - supabase-db
    environment:
      GOTRUE_DB_DATABASE_URL: 'postgres://postgres:examplepass@supabase-db:5432/postgres'
Sample Program

This Docker Compose file runs the main Supabase services: database, authentication API, and realtime server. It uses a password you set to secure the database. You can start all services by running docker-compose up in the folder with this file.

Supabase
version: '3.6'
services:
  supabase-db:
    image: supabase/postgres:latest
    ports:
      - '5432:5432'
    environment:
      POSTGRES_PASSWORD: mysecretpassword
  supabase-api:
    image: supabase/gotrue:latest
    ports:
      - '9999:9999'
    depends_on:
      - supabase-db
    environment:
      GOTRUE_DB_DRIVER: 'postgres'
      GOTRUE_DB_DATABASE_URL: 'postgres://postgres:mysecretpassword@supabase-db:5432/postgres'
  supabase-realtime:
    image: supabase/realtime:latest
    ports:
      - '4000:4000'
    depends_on:
      - supabase-db
    environment:
      DB_HOST: supabase-db
      DB_PORT: 5432
      DB_USER: postgres
      DB_PASSWORD: mysecretpassword
      DB_NAME: postgres
OutputSuccess
Important Notes

Always use strong passwords for your database to keep data safe.

Make sure Docker and Docker Compose are installed before running the configuration.

Self-hosting means you handle updates and backups yourself.

Summary

Self-hosting Supabase gives you full control over your backend.

You use Docker Compose to run Supabase services easily on your machine or server.

Remember to secure your database and manage the services regularly.