Skip to content

Enable Supabase migrations from inside Docker container#7

Open
dylanonelson wants to merge 3 commits into
mainfrom
fix/docker-supabase-migrations
Open

Enable Supabase migrations from inside Docker container#7
dylanonelson wants to merge 3 commits into
mainfrom
fix/docker-supabase-migrations

Conversation

@dylanonelson
Copy link
Copy Markdown
Owner

@dylanonelson dylanonelson commented Mar 1, 2026

Summary

  • Install Supabase CLI in claude.Dockerfile so the agent can run migration commands
  • Inject SUPABASE_DB_URL env var via run-claude-in-docker.sh, pointing to host.docker.internal:54322 so the CLI reaches the host's Postgres instead of the container's own localhost
  • Log migration commands in init.sh Docker mode so the agent knows how to use it

Context

The agent container could reach the Supabase API (port 54321) for the web app via host.docker.internal, but the Supabase CLI was not installed and had no way to reach the Postgres database (port 54322) for running migrations. This adds the CLI and wires up the connection.

Usage from inside the container:

supabase migration up --db-url "$SUPABASE_DB_URL"
supabase db push --db-url "$SUPABASE_DB_URL"

Test plan

  • Rebuild the Docker image with scripts/build-claude-in-docker.sh
  • Run scripts/run-claude-in-docker.sh with local Supabase running on the host
  • Inside the container, verify supabase --version works
  • Verify echo $SUPABASE_DB_URL prints the correct connection string
  • Run supabase migration up --db-url "$SUPABASE_DB_URL" and confirm migrations apply successfully

🤖 Generated with Claude Code

The agent container could not run `supabase migration up` or `db push`
because (1) the Supabase CLI was not installed and (2) the CLI defaults
to localhost:54322 which, inside the container, is the container itself
rather than the host running Supabase.

- Install `supabase` CLI globally in claude.Dockerfile
- Inject SUPABASE_DB_URL env var (host.docker.internal:54322) via
  run-claude-in-docker.sh so every shell has it
- Log available migration commands in init.sh Docker mode

Usage from inside the container:
  supabase migration up --db-url "$SUPABASE_DB_URL"
  supabase db push --db-url "$SUPABASE_DB_URL"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 1, 2026

Deploying timer with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9e84097
Status: ✅  Deploy successful!
Preview URL: https://2b112559.timer-cx7.pages.dev
Branch Preview URL: https://fix-docker-supabase-migratio.timer-cx7.pages.dev

View logs

dylanonelson and others added 2 commits March 1, 2026 01:39
The `supabase` npm package blocks global installs. Switch to downloading
the pre-built binary from GitHub releases, which also auto-detects the
architecture (amd64/arm64) via dpkg.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of requiring agents to remember `--db-url "$SUPABASE_DB_URL"`
on every migration command, install a wrapper script as the `supabase`
command that automatically appends --db-url for subcommands that accept
it (db push, db pull, db diff, migration up, etc.) when SUPABASE_DB_URL
is set. The real binary lives at supabase-bin.

Agents can now just run `supabase db push` and it works transparently
in both local and Docker environments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant