Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/supabase/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ All service containers are started by default. You can exclude those not needed
> It is recommended to have at least 7GB of RAM to start all services.

Health checks are automatically added to verify the started containers. Use `--ignore-health-check` flag to ignore these errors.

> If the CLI is running inside a dev container with the Docker socket bind-mounted, set the `SUPABASE_HOSTNAME` environment variable to the hostname reachable from inside that container, such as `host.docker.internal`.
6 changes: 6 additions & 0 deletions internal/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ func ValidateFunctionSlug(slug string) error {
}

func GetHostname() string {
// Overrides the host for local service connections. Useful when
// running inside a dev container when the Docker host is not
// 127.0.0.1 (container's own loopback).
if h := os.Getenv("SUPABASE_HOSTNAME"); h != "" {
return h
}
host := Docker.DaemonHost()
if parsed, err := client.ParseHostURL(host); err == nil && parsed.Scheme == "tcp" {
if host, _, err := net.SplitHostPort(parsed.Host); err == nil {
Expand Down
12 changes: 12 additions & 0 deletions internal/utils/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ func TestAssertProjectRefIsValid(t *testing.T) {
})
}

func TestGetHostname(t *testing.T) {
t.Run("returns SUPABASE_HOSTNAME when set", func(t *testing.T) {
t.Setenv("SUPABASE_HOSTNAME", "host.docker.internal")
assert.Equal(t, "host.docker.internal", GetHostname())
})

t.Run("returns 127.0.0.1 when SUPABASE_HOSTNAME is not set", func(t *testing.T) {
t.Setenv("SUPABASE_HOSTNAME", "")
assert.Equal(t, "127.0.0.1", GetHostname())
})
}

func TestWriteFile(t *testing.T) {
t.Run("writes file with directories", func(t *testing.T) {
fsys := afero.NewMemMapFs()
Expand Down
Loading