首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >授权SpiceDB:未能创建Postgres数据存储,未能连接

授权SpiceDB:未能创建Postgres数据存储,未能连接
EN

Stack Overflow用户
提问于 2022-05-18 08:26:24
回答 1查看 274关注 0票数 0

我已经创建了一个Postgres数据库,该数据库在5432端口上本地运行。数据库位于Docker容器中。当我试图将这个数据库连接到SpiceDB (另一个Docker容器)时,我会收到错误消息。

代码语言:javascript
运行
复制
"error":"failed to create datastore: unable to instantiate datastore: 
failed to connect to `host=localhost user=postgres database=spicedb`: 
dial error (dial tcp [::1]:5432: connect: cannot assign requested address)",
"time":"2022-05-18T07:48:10Z","message":
"terminated with errors"

该数据库名为"spicedb“,没有任何表。对于如何正确连接SpiceDB和Postgres,有什么想法吗?

代码语言:javascript
运行
复制
docker run --name spicedb -p 50051:50051 \
  --rm authzed/spicedb serve 
  --grpc-preshared-key "<my-key>" \
  --datastore-engine=postgres \
  --datastore-conn-uri="postgres://postgres:<db-password>@localhost:5432/spicedb?sslmode=disable"
代码语言:javascript
运行
复制
{"level":"info","new level":"info","time":"2022-05-18T07:48:10Z","message":"set log level"}
{"level":"info","new provider":"none","time":"2022-05-18T07:48:10Z","message":"set tracing provider"}
{"level":"warn","version":"1.7.1","time":"2022-05-18T07:48:10Z","message":"not running a released version of SpiceDB"}
{"level":"info","time":"2022-05-18T07:48:10Z","message":"using postgres datastore engine"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: connect: cannot assign requested address)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"info","module":"pgx","host":"localhost","time":"2022-05-18T07:48:10Z","message":"Dialing PostgreSQL server"}
{"level":"error","module":"pgx","err":"failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: operation was canceled)","time":"2022-05-18T07:48:10Z","message":"connect failed"}
{"level":"error","error":"failed to create datastore: unable to instantiate datastore: failed to connect to `host=localhost user=postgres database=spicedb`: dial error (dial tcp [::1]:5432: connect: cannot assign requested address)","time":"2022-05-18T07:48:10Z","message":"terminated with errors"}
EN

回答 1

Stack Overflow用户

发布于 2022-05-18 13:58:14

如果localhost位于两个不同的容器中,则无法使用它们作为主机名。您应该使用用户定义的网桥网络,并按容器名对postgres实例进行寻址。

来自Docker的文档在这里:https://docs.docker.com/network/bridge/

创建桥梁网络:

代码语言:javascript
运行
复制
docker network create spicedb-net

使用容器名称在网络上运行postgres:

代码语言:javascript
运行
复制
docker run --name spicedb-datastore \
  --network spicedb-net
  -e POSTGRES_PASSWORD=<db-password> \
  -d postgres

运行SpiceDB并使用您的容器名作为postgres的主机名。

代码语言:javascript
运行
复制
docker run --name spicedb -p 50051:50051 \
  --network spicedb-net
  --rm authzed/spicedb serve 
  --grpc-preshared-key "<my-key>" \
  --datastore-engine=postgres \
  --datastore-conn-uri="postgres://postgres:<db-password>@spicedb-datastore:5432/spicedb?sslmode=disable"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72285637

复制
相关文章

相似问题

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