Requirements

Set up your project

  1. Create a project dir and grab the latest .env template
mkdir trigger-docker && cd trigger-docker
curl -L https://github.com/triggerdotdev/docker/raw/main/.env.example > .env
  1. Generate secrets with openssl rand -hex 16 for the following variables:
Do NOT just copy and paste this. Generate your own secrets instead!
.env (excerpt)
...
MAGIC_LINK_SECRET=15600f1236e568d6c9c400a94e16a4ed
SESSION_SECRET=8d92078940c89588fc8b6f5481f2c6e0
ENCRYPTION_KEY=1189c93e399856a2a9a1454496171b2e
...
  1. Set NODE_ENV to production:
.env (excerpt)
...
NODE_ENV=production
...

Create a Supabase DB

Alternative: Self-host Supabase
  1. No account yet? Click here to complete onboarding

  2. Create a new project

Supabase - New Project
  1. Make a note of your password, we’ll need it in a moment
Supabase - Project Password
  1. Wait until your project has finished setting up
Supabase - Project Setup
  1. Navigate to Project Settings -> Database and copy your database connection string
Supabase - Database URL
  1. Paste it into your .env file, and append ?schema=triggerdotdev
Don’t forget to replace <PASSWORD> with the project password you set in Step 3.
.env (excerpt)
...
DATABASE_URL=postgresql://postgres:<PASSWORD>@db.<ID>.supabase.co:5432/postgres?schema=triggerdotdev
...
  1. The complete file should look something like this now:
.env
LOGIN_ORIGIN=http://localhost:3030
APP_ORIGIN=http://localhost:3030
PORT=3030
REMIX_APP_PORT=3030

MAGIC_LINK_SECRET=15600f1236e568d6c9c400a94e16a4ed
SESSION_SECRET=8d92078940c89588fc8b6f5481f2c6e0
ENCRYPTION_KEY=1189c93e399856a2a9a1454496171b2e

DATABASE_URL=postgresql://postgres:<PASSWORD>@db.<ID>.supabase.co:5432/postgres?schema=triggerdotdev
DIRECT_URL=${DATABASE_URL}

NODE_ENV=production
RUNTIME_PLATFORM=docker-compose

Self-host Trigger.dev with docker compose

  1. Create a docker compose file in your project dir
docker-compose.yml
---
version: "3.8"

services:
  triggerdotdev:
    image: ghcr.io/triggerdotdev/trigger.dev:latest
    container_name: triggerdotdev
    restart: unless-stopped
    env_file:
      - .env
    ports:
      - 3030:3030
  1. Start your docker container
docker compose up
  1. Wait for the database setup to finish - this might take a while

  2. You should now be able to visit http://localhost:3030 and see this screen:

Trigger.dev - Login
  1. Click “Continue with Email”, enter your email address and hit submit

  2. Grab the magic link from your terminal and proceed with account creation

Trigger.dev - CLI Magic Link
  1. If everything went well, the triggerdotdev and graphile_worker schemas should now be populated. Check your Supabase DB dashboard to be sure:
Supabase - Database Seed
  1. Congratulations, you’re all set up and ready to go with Supabase and Docker! 🚀

Bonus: Connection pooling

What is connection pooling?

Supabase - Connection Pool

Connection Pool - © 2023 Supabase, Apache License 2.0

When running on a single server, our app can be trusted to manage its own connections - it knows how many are open and can process its internal queue as needed.

changes things. Here, many concurrent app instances are started, each unaware of the others’ connections. This can lead to a huge - potentially fatal - increase in connections straight to your DB.

PostgreSQL has a default connection limit of 100.

External connection pools solve this by putting an additional layer between client and server, which essentially works like a message queue that gets processed as limits allow. The clients are blind to this and can keep sending their requests as before.

Enable connection pooling

  1. Copy and paste the connection string from earlier to DIRECT_URL
.env (excerpt)
...
DIRECT_URL=postgresql://postgres:<PASSWORD>@db.<ID>.supabase.co:5432/postgres?schema=triggerdotdev
...
  1. Navigate to Project Settings -> Database and copy your connection pool URL
Supabase - Connection Pool URL
  1. Paste it into your .env file next to DATABASE_URL

  2. Append ?schema=triggerdotdev&pgbouncer=true and insert your password

.env (excerpt)
...
# notice the differing ports and additional query param
DATABASE_URL=postgresql://postgres:<PASSWORD>@db.<ID>.supabase.co:6543/postgres?schema=triggerdotdev&pgbouncer=true
DIRECT_URL=postgresql://postgres:<PASSWORD>@db.<ID>.supabase.co:5432/postgres?schema=triggerdotdev
...
  1. All done! You can now enjoy the benefits of connection pooling ⚡️

Next steps