Skip to content

feat: add SUPABASE_HOSTNAME env var to override local service host#4947

Open
kanaka wants to merge 1 commit intodevelopfrom
kanaka/hostname-env-var
Open

feat: add SUPABASE_HOSTNAME env var to override local service host#4947
kanaka wants to merge 1 commit intodevelopfrom
kanaka/hostname-env-var

Conversation

@kanaka
Copy link
Copy Markdown

@kanaka kanaka commented Mar 10, 2026

Allows the CLI to work correctly when run inside a dev container with the Docker socket bind-mounted. In that context 127.0.0.1 is the container's own loopback, not the Docker host.

Set SUPABASE_HOSTNAME=host.docker.internal to reach sibling containers via Docker Desktop's host gateway without proxying the Docker socket.


AI assistance: Claude Sonnet 4.6 in Pi Agent

  • Used to find root cause, propose fix options, draft code/test/docs.
  • I ran supabase start inside the dev container, confirmed all services healthy, reviewed/edited all code changes/text.

What kind of change does this PR introduce?

Feature

What is the current behavior?

If supbase start is run from a sibling container (e.g. with /var/run/docker.sock mounted from the host), the command is unable to connect to the those containers after starting them in order to do health checks:

$ cli/supabase start
supabase_rest_mal container logs:
10/Mar/2026:16:01:56 +0000: Starting PostgREST 14.5...
10/Mar/2026:16:01:56 +0000: Admin server listening on 0.0.0.0:3001
...
Stopping containers...
failed to execute http request: Head "http://127.0.0.1:54321/rest-admin/v1/ready": dial tcp 127.0.0.1:54321: connect: connection refused
failed to execute http request: Head "http://127.0.0.1:54321/functions/v1/_internal/health": dial tcp 127.0.0.1:54321: connect: connection refused

What is the new behavior?

$ SUPABASE_HOSTNAME=host.docker.internal cli/supabase start
Starting containers...
Started supabase local development setup.
...

@kanaka kanaka requested a review from a team as a code owner March 10, 2026 16:05
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 880e4b38-efd0-4e22-8cc7-1f1e0b43ccd8

📥 Commits

Reviewing files that changed from the base of the PR and between 0335b24 and bbceb86.

📒 Files selected for processing (3)
  • docs/supabase/start.md
  • internal/utils/misc.go
  • internal/utils/misc_test.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • CLI now supports environment variable configuration for hostname resolution in containerized environments.
  • Documentation

    • Added guidance for configuring the CLI when running inside Docker containers with socket bind-mounting.
  • Tests

    • Added test coverage for hostname environment variable configuration.

Walkthrough

The changes add support for a new SUPABASE_HOSTNAME environment variable to allow users to override the hostname used when the CLI runs inside a dev container with Docker socket bind-mounted. The GetHostname function in internal/utils/misc.go is updated to check this environment variable first, and if set, returns its value; otherwise, it retains the existing logic of deriving the host from Docker.DaemonHost(). Documentation is added to advise users on setting this variable, and tests are added to verify the environment-based behavior of the GetHostname function.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 10, 2026

Coverage Report for CI Build 25005058980

Coverage decreased (-0.005%) to 63.748%

Details

  • Coverage decreased (-0.005%) from the base build.
  • Patch coverage: 6 of 6 lines across 1 file are fully covered (100%).
  • 5 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

5 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
internal/utils/git.go 5 57.14%

Coverage Stats

Coverage Status
Relevant Lines: 15624
Covered Lines: 9960
Line Coverage: 63.75%
Coverage Strength: 7.02 hits per line

💛 - Coveralls

Allows the CLI to work correctly when run inside a dev container with
the Docker socket bind-mounted. In that context 127.0.0.1 is the
container's own loopback, not the Docker host.

Set SUPABASE_HOSTNAME=host.docker.internal to reach sibling containers
via Docker Desktop's host gateway without proxying the Docker socket.

---

AI assistance: Claude Sonnet 4.6 in Pi Agent
- Used to find root cause, propose fix options, draft code/test/docs.
- I ran supabase start inside the dev container, confirmed all services
  healthy, reviewed/edited all code changes/text.
@kanaka kanaka force-pushed the kanaka/hostname-env-var branch from bbceb86 to b1eaa19 Compare April 27, 2026 15:47
Comment thread internal/utils/misc.go
Comment on lines +262 to +264
if h := os.Getenv("SUPABASE_HOSTNAME"); h != "" {
return h
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpcik

Naming is broad I think SUPABASE_HOSTNAME reads like it could refer to the hosted Supabase API or remote project hostname. Something like SUPABASE_LOCAL_HOSTNAME or SUPABASE_DOCKER_HOST more precisely scopes it to local-services networking and is harder to misuse.

Copy link
Copy Markdown
Author

@kanaka kanaka Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avallete Happy to rename this to make it more clear. SUPABASE_LOCAL_HOSTNAME and SUPBASE_DOCKER_HOST aren't quite right because this value is the opposite of that: it is an override for where to communicate with the supabase services when they don't live at localhost (i.e. they are not reachable at the same location as the docker host).

Richer context: right now the supabase service host location and the docker socket host location are same concept. I added this so that the CLI can communicate with the supabase services at a separate location from where the docker control socket lives. My concrete case is running an LLM agent in a container that has the host's docker socket mounted into that container. The sibling containers for supabase service are started via the docker control socket, but then the command tries to connect to localhost to reach the supabase services to check project health. That fails because localhost inside the LLM agent container is not where the supabase services are listening (they have ports bound to the host's localhost, not the LLM agent container's localhost). In theory, you actually could set SUPABASE_HOSTNAME to a remote location (although I haven't tested that specifically).

Maybe SUPBASE_SERVICES_HOSTNAME or SUPABASE_HOSTNAME_OVERRIDE?

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.

3 participants