supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.02k stars 201 forks source link

Connecting to localhost from within the db container not working #2022

Closed supermar1010 closed 6 months ago

supermar1010 commented 6 months ago

Describe the bug

Connecting to the docker host from the postgresql via pg_net is not possible.

To Reproduce Steps to reproduce the behavior:

  1. Have some service ruuning on your machine, just something which can serve http requests.
  2. supabase start to start the local dev env
  3. Go to the sql tab select net.http_get('http://host.docker.internal:3000/');
  4. See the 'Couldn't connect to server' error message in the _http_response table

Expected behavior

I expected to be able to connect to localhost from inside the db container.

System information Rerun the failing command with --create-ticket flag (preferred).

I tried debugging this myself: I had a look here (https://github.com/supabase/cli/blob/b0082f9983cb64f90f0714e8807389f6a1f1ff58/internal/db/start/start.go#L103) to see how the db docker container is configured.

I noticed that it is missing the NetworkMode: 'host'. The gen types command has this param, and has no problems connecting to localhost (https://github.com/supabase/cli/blob/b0082f9983cb64f90f0714e8807389f6a1f1ff58/internal/gen/types/typescript/typescript.go#L76).

I also tried compiling myself to add this param, but I always end up getting an error message, because the docker daemon couldn't find the network.

supermar1010 commented 6 months ago

I can say the oldest trick in the book fixed it. Rebooting my machine.