我正在尝试将 Postgres docker 容器连接到我的 Rust 容器。我正在使用以下 docker-compose.yml
:
version: '3'
services:
db:
image: "postgres"
restart: always
environment:
POSTGRES_PASSWORD: abcdefg
web:
build: .
ports:
- "4000:4000"
environment:
ROCKET_DATABASES: '{postgres={url="postgres://postgres:abcdefg@db:5432/postgres"}}'
但是,我收到以下错误:
db_1 | 2019-06-09 01:16:29.135 UTC [30] FATAL: password authentication failed for user "postgres"
db_1 | 2019-06-09 01:16:29.135 UTC [30] DETAIL: Password does not match for user "postgres".
db_1 | Connection matched pg_hba.conf line 95: "host all all all md5"
或者,在网络端:
web_1 | Error: FATAL: password authentication failed for user "postgres"
现在,我将环境变量 POSTGRES_PASSWORD
设置为 abcdefg
,并将连接 url 设置为 postgres://postgres:abcdefg@db:5432/postgres
,这样应该没问题,不是吗?
快速澄清一下,url 中有很多“postgres”,但基本上第一个是 url 的前缀,第二个是用户名,第三个是数据库名称。
我是否漏掉了一些明显的东西?
最佳答案
这是一个蹩脚的答案,但我通过添加一个 POSTGRES_DB
变量设置为不同的数据库名称(在我的例子中是“aletheia”)并更改 url 来解决这个问题。我不知道为什么会这样,但确实如此。
关于postgresql - 使用 Docker-Compose 验证 Postgres 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56511291/