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.
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:
host.docker.internal to access the host's networkOn Linux:
--network="host" in your docker run commandIf 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,
localhostpoints 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.internalto access the host's networkOn Linux:
- Start the container process with
--network="host"in yourdocker runcommand
It worked, thank you !
Closing this issue. Please feel free to reopen if there is more to add.
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,
localhostpoints 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:
host.docker.internalto access the host's networkOn Linux:
--network="host"in yourdocker runcommand