- 在 WSL2 中运行的 Docker 桌面 (windows10)
- 在 WSL2 中运行的 postgresql
- 在 windows10 中运行的 pgadmin
我可以使用默认设置将 pgadmin(本地机器)连接到 postgresql(本地机器 WSL2) (本地主机:5432)
postgres.conf
listen_addresses = '*'
port = 5432
当我创建一个 docker 容器时,它不会连接到我的本地 postgresql。
WSL2中使用的cmd
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
错误
"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"}
我错过了什么?
最佳答案
原来我不得不使用这个:
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 的。似乎也适用于 Docker Desktop Windows10(WSL2)。
关于postgresql - 将 hasura 连接到现有的 postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65290630/