Search code examples
postgresqldockerhasura

connect hasura to existing postgresql


  • Docker desktop (windows10) running in WSL2
  • postgresql running in WSL2
  • pgadmin running in windows10

I can connect with pgadmin (local machine) to postgresql (localmachine WSL2) with the default settings (localhost:5432)

postgres.conf

listen_addresses = '*'
port = 5432

When I create a docker container it will not connect to my local postgresql.

cmd used in WSL2

docker run -d --net=host \
       -e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:password@localhost:5432/mydb \
       -e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
       -e HASURA_GRAPHQL_DEV_MODE=true \
       hasura/graphql-engine:v1.3.3

error

"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"}

What am I missing?


Solution

  • turned out I had to use this:

    docker run -d -p 8080:8080 
    -e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:[email protected]:5432/mydb \      
    -e HASURA_GRAPHQL_ENABLE_CONSOLE=true  \
    -e HASURA_GRAPHQL_DEV_MODE=true        \
    hasura/graphql-engine:v1.3.3
    

    I thought "host.docker.internal" was only ment for Mac. Seems to work with Docker Desktop Windows10(WSL2) too.