首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将hasura连接到现有postgresql

将hasura连接到现有postgresql
EN

Stack Overflow用户
提问于 2020-12-14 14:20:47
回答 2查看 1K关注 0票数 3

在WSL2

  • postgresql中运行的
  • Docker桌面(windows10)运行在WSL2
  • pgadmin中运行在windows10

我可以使用默认设置(localhost:5432)与pgadmin (本地机器)连接到postgresql (localmachine WSL2)。

postgres.conf

代码语言:javascript
复制
listen_addresses = '*'
port = 5432

当我创建一个码头容器时,它将不会连接到本地postgresql。

WSL2中的cmd

代码语言:javascript
复制
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

错误

代码语言:javascript
复制
"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"}

我遗漏了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-12-14 14:45:33

结果我不得不用这个:

代码语言:javascript
复制
docker run -d -p 8080:8080 
-e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:password@host.docker.internal:5432/mydb \      
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true  \
-e HASURA_GRAPHQL_DEV_MODE=true        \
hasura/graphql-engine:v1.3.3

我以为"host.docker.internal“只适用于Mac。似乎也适用于Desktop Windows10(WSL2)。

票数 3
EN

Stack Overflow用户

发布于 2022-02-28 21:45:22

这是我的解决方案,重要的是主机名。

代码语言:javascript
复制
version: "3.8"

services: 

postgres:
    restart: always
    image: postgres
    container_name: postgres
    hostname: postgres
    #depends_on:
        #sql-server:
            #condition: service_healthy
    volumes:
        - pg_data:/var/lib/postgresql/data
    environment:
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: postgrespassword

    networks:
        - backend

sql-api:
    restart: always
    container_name: api
    image: hasura/graphql-engine:v2.2.0
    ports:
        - 8055:8080
    depends_on:
        - "postgres"
    hostname: sqlapi
    environment:
        ## postgres database to store Hasura metadata
        HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
        ## enable the console served by server
        HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
        ## enable debugging mode. It is recommended to disable this in production
        HASURA_GRAPHQL_DEV_MODE: "true"
        HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
        ## uncomment next line to set an admin secret
        # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey

    networks:
        - backend

网络:后端:驱动:桥

卷: pg_data:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65290630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档