gpt4 book ai didi

postgresql - 如何将 Pact Broker 连接到 PostgreSQL 的本地或云实例?

转载 作者:行者123 更新时间:2023-12-02 07:54:41 26 4
gpt4 key购买 nike

我正在努力让 Pact Broker 在 Docker 容器中运行,以连接到我在 Windows 上本地安装的 PostgreSQL。

这就是我的 docker run 命令的样子...

docker run pactfoundation/pact-broker 
-e PACT_BROKER_DATABASE_USERNAME=pact_broker
-e PACT_BROKER_DATABASE_PASSWORD={Password}
-e PACT_BROKER_DATABASE_HOST=host.docker.internal
-e PACT_BROKER_DATABASE_NAME=pact_broker
-e PACT_BROKER_DATABASE_PORT=5432
-p 9292:9292

返回以下错误...

Unable to load application: Sequel::DatabaseConnectionError: PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
bundler: failed to load command: puma (/pact_broker/vendor/bundle/ruby/2.6.0/bin/puma)
Sequel::DatabaseConnectionError: PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

这是我在 pgAdmin 4 中的数据库和用户

enter image description here

这是我用来测试连接的命令

psql postgresql://pact_broker:{Password}@localhost/pact_broker

返回以下内容...

psql (13.3)
WARNING: Console code page (65001) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.

pact_broker=>

我还尝试运行以下命令,该命令返回相同的错误

docker run pactfoundation/pact-broker -e PACT_BROKER_DATABASE_URL=postgresql://pact_broker:{Password}@host.docker.internal/pact_broker -p 9292:9292

我的 postgres.conf 文件包含 listen_addresses = '*' 并且我的 pg_hba.conf 包含以下内容

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all scram-sha-256
host all all 0.0.0.0/0 trust
host replication all ::1/128 scram-sha-256
host all all ::/0 md5

我在使用 Azure Database for PostgreSQL 托管的实例时遇到类似问题

我的连接字符串如下所示...

psql "host=pactbrokerserver.postgres.database.azure.com port=5432 dbname={your_database} user=postgres@pactbrokerserver password={your_password} sslmode=require"

我尝试通过本地协议(protocol)代理连接到...

docker run pactfoundation/pact-broker 
-e PACT_BROKER_DATABASE_USERNAME=postgres@pactbrokerserver
-e PACT_BROKER_DATABASE_PASSWORD={Password}
-e PACT_BROKER_DATABASE_HOST=pactbrokerserver.postgres.database.azure.com
-e PACT_BROKER_DATABASE_NAME=pactbroker
-e PACT_BROKER_DATABASE_PORT=5432
-e PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES=5
-p 9292:9292

它返回完全相同的错误。

这里可能存在什么问题?

enter image description here

最佳答案

我认为这里发生的情况是,您已将容器名称放在 docker run 命令的环境参数列表之前。

因此,您无需使用自定义值来设置正在运行的容器的 PACT_BROKER_DATABASE_NAME 和其他环境变量,它们只是被运行时丢弃。

试试这个:

docker run -e PACT_BROKER_DATABASE_USERNAME=pact_broker \
-e PACT_BROKER_DATABASE_PASSWORD={Password} \
-e PACT_BROKER_DATABASE_HOST=host.docker.internal \
-e PACT_BROKER_DATABASE_NAME=pact_broker \
-e PACT_BROKER_DATABASE_PORT=5432 \
-p 9292:9292 \
pactfoundation/pact-broker

调试选项

如果我错了,问题可能与网络路径相关。为了排除这种情况,我们可以通过用 /bin/sh 替换入口点(通常是启动和运行 Web 服务器的脚本)来获取 docker 容器中的 shell:

docker run -it --entrypoint /bin/sh --user root -e PACT_BROKER_DATABASE_USERNAME=pact_broker -e PACT_BROKER_DATABASE_PASSWORD=Penwater858 -e PACT_BROKER_DATABASE_HOST=host.docker.internal -e PACT_BROKER_DATABASE_NAME=pact_broker -e PACT_BROKER_DATABASE_PORT=5432 -p 9292:9292 pactfoundation/pact-broker
# once in the container...
apk update
apk add busybox-extras
# see if there is a network path
telnet $PACT_BROKER_DATABASE_HOST $PACT_BROKER_DATABASE_PORT

关于postgresql - 如何将 Pact Broker 连接到 PostgreSQL 的本地或云实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67957118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com