Connection refused Error, cannot connect to my postgres database with docker
See original GitHub issueHi 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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
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 yourdocker run
commandIt worked, thank you !