Bird
Raised Fist0
Supabasecloud~5 mins

Self-hosting Supabase

Choose your learning style10 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.

Practice

(1/5)
1. What is the main benefit of self-hosting Supabase compared to using the hosted service?
easy
A. It provides free hosting without limits.
B. It automatically scales without any setup.
C. You don't need to manage any servers or updates.
D. You get full control over your backend and data.

Solution

  1. Step 1: Understand self-hosting meaning

    Self-hosting means you run the service on your own machine or server, giving you control.
  2. Step 2: Compare benefits

    Unlike hosted services, self-hosting lets you manage data and backend fully, but requires maintenance.
  3. Final Answer:

    You get full control over your backend and data. -> Option D
  4. Quick Check:

    Self-hosting = full control [OK]
Hint: Self-hosting means you control your backend fully [OK]
Common Mistakes:
  • Thinking self-hosting means no maintenance needed
  • Assuming self-hosting is always free
  • Confusing self-hosting with automatic scaling
2. Which command is used to start Supabase services using Docker Compose?
easy
A. supabase start
B. docker compose up -d
C. docker start supabase
D. docker run supabase

Solution

  1. Step 1: Identify Docker Compose usage

    Supabase self-hosting uses Docker Compose to manage multiple services together.
  2. Step 2: Recall correct Docker Compose command

    The command to start services in detached mode is docker compose up -d.
  3. Final Answer:

    docker compose up -d -> Option B
  4. Quick Check:

    Start services with docker compose up -d [OK]
Hint: Use 'docker compose up -d' to start all services [OK]
Common Mistakes:
  • Using 'docker start' which starts single containers only
  • Typing 'supabase start' which is not a Docker command
  • Using 'docker run' which runs a new container, not compose
3. Given this Docker Compose snippet for Supabase services:
services:
  db:
    image: supabase/postgres:latest
  api:
    image: supabase/api:latest
    depends_on:
      - db

What happens if you run docker compose up?
medium
A. Both db and api services start, with api waiting for db.
B. Only db service starts, api is ignored.
C. api starts before db, causing errors.
D. No services start due to missing volumes.

Solution

  1. Step 1: Understand depends_on behavior

    The depends_on means api waits for db container to start before launching.
  2. Step 2: Analyze docker compose up effect

    Running docker compose up starts all defined services; api waits for db as specified.
  3. Final Answer:

    Both db and api services start, with api waiting for db. -> Option A
  4. Quick Check:

    depends_on makes api wait for db [OK]
Hint: depends_on ensures service start order in Docker Compose [OK]
Common Mistakes:
  • Thinking depends_on delays start until db is ready (it waits only for start)
  • Assuming api won't start without volumes (not required here)
  • Believing only one service starts by default
4. You tried to start Supabase with Docker Compose but get a database connection error. Which fix is most likely correct?
medium
A. Change the Supabase API image to an older version.
B. Remove the Docker Compose file and reinstall Docker.
C. Check if the database service is running and accessible.
D. Disable the firewall on your local machine.

Solution

  1. Step 1: Identify cause of connection error

    Database connection errors usually mean the database service is down or unreachable.
  2. Step 2: Verify database service status

    Check if the database container is running and network settings allow access.
  3. Final Answer:

    Check if the database service is running and accessible. -> Option C
  4. Quick Check:

    Database connection error = check DB service [OK]
Hint: Verify database container is running first [OK]
Common Mistakes:
  • Assuming reinstalling Docker fixes connection errors
  • Changing API image without checking DB status
  • Disabling firewall without confirming network issues
5. You want to secure your self-hosted Supabase database. Which practice is best to protect your data?
hard
A. Use strong passwords, restrict network access, and enable SSL connections.
B. Run the database on default ports and allow all IPs.
C. Disable authentication to simplify access for developers.
D. Store database backups on the same server without encryption.

Solution

  1. Step 1: Identify security best practices

    Strong passwords, network restrictions, and SSL protect data from unauthorized access.
  2. Step 2: Evaluate other options

    Default ports and open IPs increase risk; disabling auth or unencrypted backups are unsafe.
  3. Final Answer:

    Use strong passwords, restrict network access, and enable SSL connections. -> Option A
  4. Quick Check:

    Secure DB = strong passwords + network + SSL [OK]
Hint: Secure DB with passwords, network limits, and SSL [OK]
Common Mistakes:
  • Leaving default ports open to the internet
  • Disabling authentication for convenience
  • Not encrypting backups or storing them insecurely
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard