Skip to content

Commit fede130

Browse files
emmaling27Convex, Inc.
authored and
Convex, Inc.
committed
Update self hosting docs to include running docker w/postgres (#34122)
GitOrigin-RevId: 147be320be8499e9466d3220431b9fb5b50ef152
1 parent f900492 commit fede130

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

self-hosted/SELFHOSTING.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Development of the Convex backend is led by the Convex team. We
2222
[love receiving feedback](https://discord.gg/convex). We keep this repository
2323
synced with any internal development work within a handful of days.
2424

25-
# Self Hosting Via Docker [recommended]
25+
# Self Hosting Via Docker
2626

2727
You'll need to have [Docker](https://docs.docker.com/desktop/) installed to run
2828
convex in Docker.
@@ -66,6 +66,13 @@ npx convex run <run args>
6666
npx convex import <import args>
6767
```
6868

69+
By default, the backend will store its data in a volume managed by Docker. Note
70+
that you'll need to set up persistent storage on whatever cloud hosting platform
71+
you choose to run the Docker container on (e.g. AWS EBS). The default database
72+
is SQLite, but for production workloads, we recommend running Convex backed by
73+
Postgres. Follow [these instructions](#self-hosting-on-postgres-with-neon) to
74+
connect to Postgres.
75+
6976
# Self Hosting with [Fly.io](https://fly.io/)
7077

7178
From the self-hosted directory, deploy the backend.
@@ -120,22 +127,40 @@ example:
120127
- And you have an HTTP action named `sendEmail`
121128
- You would call it at `https://self-hosted-backend.fly.dev/http/sendEmail`
122129

123-
## Connecting to [Neon Postgres](https://neon.tech)
130+
# Self Hosting on Postgres with [Neon](https://neon.tech)
124131

125132
Create a project on Neon. Copy the connection string from the Neon dashboard.
126133

127134
```sh
128135
export DATABASE_CONNECTION='<connection string>'
136+
```
129137

130-
# Create the database
138+
Create the database
139+
140+
```sh
131141
psql $DATABASE_CONNECTION -c "CREATE DATABASE convex_self_hosted"
142+
```
143+
144+
Strip database name and query params from the connection string. It should end
145+
in neon.tech
132146

133-
# Strip database name and query params from the connection string. It should end in neon.tech
147+
```sh
134148
export DATABASE_URL=$(echo $DATABASE_CONNECTION | sed -E 's/\/[^/]+(\?.*)?$//')
149+
```
150+
151+
Update your `DATABASE_URL` environment variable. If you're deploying on
152+
[Fly](https://fly.io):
153+
154+
```sh
135155
fly secrets set DATABASE_URL=$DATABASE_URL
156+
```
157+
158+
After you've deployed with the environment variable set, check that the database
159+
is connected to your self-hosted convex backend. There should be a line like
160+
"Connected to Postgres" in the logs. If you're deploying on
161+
[Fly](https://fly.io):
136162

137-
# Check that the database is connected to your self-hosted convex backend.
138-
# There should be a line like "Connected to Postgres" in the logs.
163+
```sh
139164
fly logs
140165
```
141166

self-hosted/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
- ACTIONS_USER_TIMEOUT_SECS=${ACTIONS_USER_TIMEOUT_SECS:-}
1414
- CONVEX_CLOUD_ORIGIN=${URL_BASE:-http://127.0.0.1}:${PORT:-3210}
1515
- CONVEX_SITE_ORIGIN=${URL_BASE:-http://127.0.0.1}:${SITE_PROXY_PORT:-3211}
16+
- DATABASE_URL=${DATABASE_URL:-}
1617
container_name: convex-local-backend
1718
healthcheck:
1819
test: curl -f http://localhost:3210/version

0 commit comments

Comments
 (0)