hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.17k stars 2.77k forks source link

Cannot connect with Host PostgreSQL Database #4870

Open SumeetMoray opened 4 years ago

SumeetMoray commented 4 years ago

i am trying to follow this tutorial https://hasura.io/docs/1.0/graphql/manual/deployment/docker/index.html

on Ubuntu 20.04 to connect hasura with exisitng database

I tried this command but it does not work

docker run -d --net=host \ -e HASURA_GRAPHQL_DATABASE_URL=postgres://username:password@hostname:port/dbname \ -e HASURA_GRAPHQL_ENABLE_CONSOLE=true \ hasura/graphql-engine:latest

Can anyone throw some light on how to connect Hasura with Local Postgres Database ...

tirumaraiselvan commented 4 years ago

If your Postgres is on localhost, then hostname in your connection string should point to the docker bridge, typically 172.17.0.1 (might differ based on OS) : https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach

SumeetMoray commented 4 years ago

I am able to run it in windows ... but not on ubuntu linux version 20.04 ... its really aweful ... something that docker developers must take a note !

mattjslaton commented 3 years ago

Yeah, it's broken for me as well. I can run hasura just fine on macos but, when I go to run it on ubuntu, hasura cannot connect to postgres. Not sure how to fix this yet.

etuned commented 3 years ago

If you are using the docker instance of Hasura, you will need to open the ports for it to work on Ubuntu. In the docker-compose.yml where it says 'ports' under the postgres container add : and repeat the numbers. It should look like this for the postgres section.

postgres: image: postgres:12 restart: always ports:

Note that GitHub may mess up the yaml formatting. Then for PG_DATABASE_URL make it connect to localhost instead of a postgres host. It looks like this PG_DATABASE_URL: postgres://postgres:postgrespassword@localhost:5432/postgres

Hope this helps and know that this is not a production ready setup.

etuned commented 3 years ago

@SumeetMoray , to answer your question about connecting to a local Postgres database, you will have to configure your Postgres database with a user and database for Hasura, and then allow connections from the docker container that runs the Hasura console in the Postgres config. Linode has a very good tutorial about how to configure postgres. View the Linode tutorial here

Hope this help.