Graphql-engine: Connection refused Error, cannot connect to my postgres database with docker

Created on 21 Apr 2020  路  3Comments  路  Source: hasura/graphql-engine

Hi Guys,
I've been trying for hours to make hasura work with docker, i have a postgres db running locally and i can reach it and access it without any problem from 3 different postgres clients for mac (postgres, postico and pgadmin), but when i try to connect graphql with docker i keep getting the following 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"}
the address seems to be correct, cause if i paste it in the browser it opens it with postico and connects correctly. I also tried playing with postgres configuration files like some stackoverflow users suggested but without any luck.

question

Most helpful comment

If I understand this correctly, you have Hasura running in a Docker container and Postgres running on your host machine? And that Hasura says it cannot connect to Postgres?

Inside of the Hasura container, localhost points to it's own container network. You want to point it to the host (your machine's) localhost.

If you use docker-compose, a network is created that allows all services to communicate with each other directly. If you're using a single Docker image running, how to fix this depends on your OS.

On Windows/Mac:

  • Use host.docker.internal to access the host's network

On Linux:

  • Start the container process with --network="host" in your docker run command

All 3 comments

If I understand this correctly, you have Hasura running in a Docker container and Postgres running on your host machine? And that Hasura says it cannot connect to Postgres?

Inside of the Hasura container, localhost points to it's own container network. You want to point it to the host (your machine's) localhost.

If you use docker-compose, a network is created that allows all services to communicate with each other directly. If you're using a single Docker image running, how to fix this depends on your OS.

On Windows/Mac:

  • Use host.docker.internal to access the host's network

On Linux:

  • Start the container process with --network="host" in your docker run command

If I understand this correctly, you have Hasura running in a Docker container and Postgres running on your host machine? And that Hasura says it cannot connect to Postgres?

Inside of the Hasura container, localhost points to it's own container network. You want to point it to the _host_ (your machine's) localhost.

If you use docker-compose, a network is created that allows all services to communicate with each other directly. If you're using a single Docker image running, how to fix this depends on your OS.

On Windows/Mac:

  • Use host.docker.internal to access the host's network

On Linux:

  • Start the container process with --network="host" in your docker run command

It worked, thank you !

Closing this issue. Please feel free to reopen if there is more to add.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

macalinao picture macalinao  路  3Comments

hooopo picture hooopo  路  3Comments

egislook picture egislook  路  3Comments

bogdansoare picture bogdansoare  路  3Comments

leoalves picture leoalves  路  3Comments