Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

docs: improving the docker guide to make it easier to byo database

Copple3a23d636778c
diff --git a/docker/.env.example b/docker/.env.example
index 44b849e48ef..5a7d3c0da24 100644
--- a/docker/.env.example
+++ b/docker/.env.example
@@ -1,12 +1,33 @@
+############
# Secrets
# YOU MUST CHANGE THESE BEFORE GOING INTO PRODUCTION
+############
POSTGRES_PASSWORD=your-super-secret-and-long-postgres-password
JWT_SECRET=your-super-secret-jwt-token-with-at-least-32-characters-long
ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE
SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q
-# Auth
+############
+# Database - You can change these to any PostgreSQL database that has logical replication enabled.
+############
+
+POSTGRES_HOST=db
+POSTGRES_DB=postgres
+POSTGRES_USER=postgres
+POSTGRES_PORT=5432
+
+############
+# API Proxy - Configuration for the Kong Reverse proxy.
+############
+
+KONG_HTTP_PORT=8000
+KONG_HTTPS_PORT=8443
+
+
+############
+# Auth - Configuration for the GoTrue authentication server.
+############
## General
SITE_URL=http://localhost:3000
@@ -28,19 +49,9 @@ SMTP_SENDER_NAME=fake_sender
ENABLE_PHONE_SIGNUP=true
ENABLE_PHONE_AUTOCONFIRM=true
-# Ports
+############
+# Studio - Configuration for the Dashboard
+############
-## Studio port
STUDIO_PORT=3000
-
-## API endpoint ports
-KONG_HTTP_PORT=8000
-KONG_HTTPS_PORT=8443
-
-## DB port
-POSTGRES_PORT=5432
-
-# Studio
-
-## Public REST endpoint - replace this if you intend to use Studio outside of localhost
-PUBLIC_REST_URL=http://localhost:8000/rest/v1/
+PUBLIC_REST_URL=http://localhost:8000/rest/v1/ # replace if you intend to use Studio outside of localhost
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 6e5fb21986c..b62db854bfd 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -42,14 +42,14 @@ services:
container_name: supabase-auth
image: supabase/gotrue:v2.5.21
depends_on:
- - db
+ - db # Disable this if you are using an external Postgres database
restart: unless-stopped
environment:
GOTRUE_API_HOST: 0.0.0.0
GOTRUE_API_PORT: 9999
GOTRUE_DB_DRIVER: postgres
- GOTRUE_DB_DATABASE_URL: postgres://postgres:${POSTGRES_PASSWORD}@db:5432/postgres?search_path=auth
+ GOTRUE_DB_DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?search_path=auth
GOTRUE_SITE_URL: ${SITE_URL}
GOTRUE_URI_ALLOW_LIST: ${ADDITIONAL_REDIRECT_URLS}
@@ -81,10 +81,10 @@ services:
container_name: supabase-rest
image: postgrest/postgrest:v9.0.0
depends_on:
- - db
+ - db # Disable this if you are using an external Postgres database
restart: unless-stopped
environment:
- PGRST_DB_URI: postgres://postgres:${POSTGRES_PASSWORD}@db:5432/postgres
+ PGRST_DB_URI: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
PGRST_DB_SCHEMAS: public,storage, graphql_public
PGRST_DB_ANON_ROLE: anon
PGRST_JWT_SECRET: ${JWT_SECRET}
@@ -94,13 +94,13 @@ services:
container_name: supabase-realtime
image: supabase/realtime:v0.22.4
depends_on:
- - db
+ - db # Disable this if you are using an external Postgres database
restart: unless-stopped
environment:
- DB_HOST: db
- DB_PORT: 5432
- DB_NAME: postgres
- DB_USER: postgres
+ DB_HOST: ${POSTGRES_HOST}
+ DB_PORT: ${POSTGRES_PORT}
+ DB_NAME: ${POSTGRES_DB}
+ DB_USER: ${POSTGRES_USER}
DB_PASSWORD: ${POSTGRES_PASSWORD}
DB_SSL: "false"
PORT: 4000
@@ -118,7 +118,7 @@ services:
container_name: supabase-storage
image: supabase/storage-api:v0.10.0
depends_on:
- - db
+ - db # Disable this if you are using an external Postgres database
- rest
restart: unless-stopped
environment:
@@ -126,7 +126,7 @@ services:
SERVICE_KEY: ${SERVICE_ROLE_KEY}
POSTGREST_URL: http://rest:3000
PGRST_JWT_SECRET: ${JWT_SECRET}
- DATABASE_URL: postgres://postgres:${POSTGRES_PASSWORD}@db:5432/postgres
+ DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
PGOPTIONS: -c search_path=storage,public
FILE_SIZE_LIMIT: 52428800
STORAGE_BACKEND: file
@@ -142,13 +142,14 @@ services:
container_name: supabase-meta
image: supabase/postgres-meta:v0.29.0
depends_on:
- - db
+ - db # Disable this if you are using an external Postgres database
restart: unless-stopped
environment:
PG_META_PORT: 8080
- PG_META_DB_HOST: db
+ PG_META_DB_HOST: ${POSTGRES_HOST}
PG_META_DB_PASSWORD: ${POSTGRES_PASSWORD}
+ # Comment out everything below this point if you are using an external Postgres database
db:
container_name: supabase-db
image: supabase/postgres:14.1.0.21
diff --git a/web/docs/guides/hosting/docker.mdx b/web/docs/guides/hosting/docker.mdx
index 89ebcfa9b03..f8a6fcc8e66 100644
--- a/web/docs/guides/hosting/docker.mdx
+++ b/web/docs/guides/hosting/docker.mdx
@@ -71,14 +71,31 @@ The Docker setup doesn't include a management database for managing users and lo
## Configuration
+Each system can be [configured](/docs/guides/hosting/overview#configuration) to suit your particular use-case.
+
To keep the setup simple, we made some choices that may not be optimal for production:
- the database is in the same machine as the servers
-- the storage uses the filesystem backend instead of S3
+- Storage uses the filesystem backend instead of S3
+- Auth should be configured with a production-ready SMTP server
+
+### Using an external database
+
+We strongly [recommend](/docs/guides/hosting/overview#managing-your-database) that you decouple your database from `docker-compose` before deploying.
+The middleware will run with any PostgreSQL database that has logical replication enabled. The following environment variables should be updated
+in the `.env` file to point to your external database:
+
+```env title=".env"
+POSTGRES_PASSWORD=your-super-secret-and-long-postgres-password
+
+POSTGRES_HOST=db
+POSTGRES_DB=postgres
+POSTGRES_USER=postgres
+POSTGRES_PORT=5432
+```
+
+Once you can done this, you can safely comment out the `db` section of the `docker-compose` file, and remove any instances where the services `depends_on` the `db` image.
-We strongly [recommend](/docs/guides/hosting/overview#managing-your-database) that you decouple your database
-before deploying.
-Each system can be [configured](/docs/guides/hosting/overview#configuration) to suit your particular use-case.
## Deploying