Buttlet
Buttlet

Reputation: 301

Hasura container cannot connect to postgres DB?

I am running a postgres db running in Docker with:

docker run -d -p 5432:5432 --name db --env POSTGRES_PASSWORD=postgres --env POSTGRES_USER=postgres postgres

I'm trying to connect Hasura to it, with this command

docker run --name hasura -p 5002:8082 --env HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:postgres@localhost:5432 -e HASURA_GRAPHQL_ENABLE_CONSOLE=true hasura/graphql-engine:latest

but I get this response:

{"type":"startup","timestamp":"2021-04-20T05:49:08.548+0000","level":"info","detail":{"kind":"server_configuration","info":{"live_query_options":{"batch_size":100,"refetch_delay":1},"transaction_isolation":"ISOLATION LEVEL READ COMMITTED","plan_cache_options":{"plan_cache_size":4000},"enabled_log_types":["http-log","websocket-log","startup","webhook-log"],"server_host":"HostAny","enable_allowlist":false,"log_level":"info","auth_hook_mode":null,"use_prepared_statements":true,"unauth_role":null,"stringify_numeric_types":false,"enabled_apis":["metadata","graphql","config","pgdump"],"enable_telemetry":true,"enable_console":true,"auth_hook":null,"jwt_secret":null,"cors_config":{"allowed_origins":"*","disabled":false,"ws_read_cookie":null},"console_assets_dir":null,"admin_secret_set":false,"port":8080}}}
{"type":"startup","timestamp":"2021-04-20T05:49:08.548+0000","level":"info","detail":{"kind":"postgres_connection","info":{"retries":1,"database_url":"postgres://postgres:...@localhost:5432"}}}
{"type":"pg-client","timestamp":"2021-04-20T05:49:08.548+0000","level":"warn","detail":{"message":"postgres connection failed, retrying(0)."}}
{"type":"pg-client","timestamp":"2021-04-20T05:49:08.548+0000","level":"warn","detail":{"message":"postgres connection failed, retrying(1)."}}
{"type":"startup","timestamp":"2021-04-20T05:49:08.548+0000","level":"error","detail":{"kind":"catalog_migrate","info":{"internal":"could not connect to server: Connection refused\n\tIs the server running on host \"localhost\" (127.0.0.1) and accepting\n\tTCP/IP connections on port 5432?\n","path":"$","error":"connection error","code":"postgres-error"}}}
{"internal":"could not connect to server: Connection refused\n\tIs the server running on host \"localhost\" (127.0.0.1) and accepting\n\tTCP/IP connections on port 5432?\n","path":"$","error":"connection error","code":"postgres-error"}

I am running Docker Desktop v3.3.1 on Windows 10.

Any help on this would be appreciated.

Thanks.

Upvotes: 1

Views: 2501

Answers (1)

ggaowp
ggaowp

Reputation: 96

As anemyte mentioned, changing localhost to host.docker.internal works for me.

Upvotes: 5

Related Questions