📖 Scenario: You want to run your own Supabase backend on your server instead of using the cloud service. This helps you control your data and customize your setup.
🎯 Goal: Set up a basic self-hosted Supabase environment using Docker Compose with the required services.
📋 What You'll Learn
Create a Docker Compose file with Supabase services
Add environment variables for configuration
Define the main Supabase service with ports and volumes
Complete the Docker Compose file to be deployable
💡 Why This Matters
🌍 Real World
Many companies prefer to self-host Supabase to keep full control over their data and infrastructure.
💼 Career
Knowing how to configure and deploy self-hosted cloud services is a valuable skill for cloud engineers and DevOps professionals.
Progress0 / 4 steps
1
Create the initial Docker Compose file
Create a file named docker-compose.yml and add the version line version: '3.8' and an empty services section.
Supabase
Hint
Start with the version and services keys in YAML format.
2
Add environment variables for Supabase
Inside the services section, add a service named supabase with an environment key containing POSTGRES_PASSWORD: examplepassword and API_PORT: 8000.
Supabase
Hint
Indent environment variables under the supabase service.
3
Define ports and volumes for Supabase service
Under the supabase service, add ports mapping 8000:8000 and volumes mapping ./data:/var/lib/postgresql/data.
Supabase
Hint
Use dash (-) for list items under ports and volumes.
4
Complete the Docker Compose file with image and restart policy
Add image: supabase/postgres:latest and restart: always under the supabase service to finalize the configuration.
Supabase
Hint
Place image and restart keys at the same level as environment, ports, and volumes.
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
Step 1: Understand self-hosting meaning
Self-hosting means you run the service on your own machine or server, giving you control.
Step 2: Compare benefits
Unlike hosted services, self-hosting lets you manage data and backend fully, but requires maintenance.
Final Answer:
You get full control over your backend and data. -> Option D
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
Step 1: Identify Docker Compose usage
Supabase self-hosting uses Docker Compose to manage multiple services together.
Step 2: Recall correct Docker Compose command
The command to start services in detached mode is docker compose up -d.
Final Answer:
docker compose up -d -> Option B
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
Step 1: Understand depends_on behavior
The depends_on means api waits for db container to start before launching.
Step 2: Analyze docker compose up effect
Running docker compose up starts all defined services; api waits for db as specified.
Final Answer:
Both db and api services start, with api waiting for db. -> Option A
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
Step 1: Identify cause of connection error
Database connection errors usually mean the database service is down or unreachable.
Step 2: Verify database service status
Check if the database container is running and network settings allow access.
Final Answer:
Check if the database service is running and accessible. -> Option C
Quick Check:
Database connection error = check DB service [OK]
Hint: Verify database container is running first [OK]