question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection refused Error, cannot connect to my postgres database with docker

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
GavinRay97commented, Apr 21, 2020

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
3reactions
ilahomesickcommented, Apr 21, 2020

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 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dockerizing PostgreSQL - psql Connection refused
Solution for me was simply using host.docker.internal instead of localhost in your connection string.
Read more >
docker-compose, postgres and connection refused!
Try to manually connect using the psql client. This failed. Check if the port is being used using netstat. No, it wasn't. Realize...
Read more >
Can't get postgres to work - Compose
I 'm building my stack with nginx, php-fpm and postgres. PHP is already working with nginx. But I can't connect to postgres.
Read more >
Cannot connect to the postgres in docker container #1681
Today I pulled the newest image of postgres: docker pull postgres And started container out of it: docker run --rm --name pg-docker -e ......
Read more >
Solved: Docker can't connect to PostgreSQL
I have an issue stating: postgresql-init_1 | psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found