英文:
phppgadmin "login failed" between containers
问题
尝试使用正确的用户名和密码设置登录数据库失败,出现了极其有帮助的错误消息"登录失败"。如下所列,我已尝试了这个问题周围找到的所有常见解决方案,但都没有成功。
- 容器在相同的网络上。
- 数据库端口是默认的,并已进行了转发。
- 可以在容器之间进行ping测试。
- 可以在主机机器上使用以下凭据登录到Postgres,并在数据库容器内部使用
psql
登录。 - 已验证
show listen_addresses;
的值为"*"。 - 监视Postgres的日志输出,在尝试使用phppgadmin登录时没有显示任何与连接相关的消息或错误。
- 为容器提供了建议和必需的环境变量。
- 我尝试更改了数据库容器的转发端口,然后更改了
PHP_PG_ADMIN_SERVER_PORT
,但没有任何区别。 netstat
确认数据库在主机上的正确端口上监听。- 我已经多次重建了容器,包括删除了Postgres的数据文件夹。
- 为了排除自动名称解析可能存在问题的情况,我尝试手动替换了数据库容器的Docker IP地址中的
PHP_PG_ADMIN_SERVER_HOST
。
docker-compose.yaml
networks:
centurion:
name: centurion-net
services:
benard:
image: postgres:latest
restart: always
volumes:
- /opt/containers/benard/persist/data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=pg
- POSTGRES_USER=pg
- POSTGRES_PASSWORD=password
ports:
- "5432:5432"
networks:
- centurion
benard_ui:
depends_on:
- benard
restart: always
image: dockage/phppgadmin:latest
ports:
- "8200:80"
environment:
- PHP_PG_ADMIN_SERVER_DESC=BENARD
- PHP_PG_ADMIN_SERVER_HOST=benard
- PHP_PG_ADMIN_SERVER_PORT=5432
- PHP_PG_ADMIN_SERVER_SSL_MODE=allow
- PHP_PG_ADMIN_SERVER_DEFAULT_DB=template1
- PHP_PG_ADMIN_SERVER_PG_DUMP_PATH=/usr/bin/pg_dump
- PHP_PG_ADMIN_SERVER_PG_DUMPALL_PATH=/usr/bin/pg_dumpall
- PHP_PG_ADMIN_DEFAULT_LANG=auto
- PHP_PG_ADMIN_AUTO_COMPLETE=default on
- PHP_PG_ADMIN_EXTRA_LOGIN_SECURITY=false
- PHP_PG_ADMIN_OWNED_ONLY=false
- PHP_PG_ADMIN_SHOW_COMMENTS=true
- PHP_PG_ADMIN_SHOW_ADVANCED=false
- PHP_PG_ADMIN_SHOW_SYSTEM=false
- PHP_PG_ADMIN_MIN_PASSWORD_LENGTH=1
- PHP_PG_ADMIN_LEFT_WIDTH=200
- PHP_PG_ADMIN_THEME=default
- PHP_PG_ADMIN_SHOW_OIDS=false
- PHP_PG_ADMIN_MAX_ROWS=30
- PHP_PG_ADMIN_MAX_CHARS=50
- PHP_PG_ADMIN_USE_XHTML_STRICT=false
- PHP_PG_ADMIN_HELP_BASE=http://www.postgresql.org/docs/%s/interactive/
- PHP_PG_ADMIN_AJAX_REFRESH=3
networks:
- centurion
英文:
Trying to enter the correct user and password set for the database fails with the extremely helpful error "login failed". As listed below, I have tried all of the common solutions for this issue as found around here, no dice yet.
- Containers are on the same network.
- The database port is the default, and is forwarded.
- Can ping between containers from within.
- Can login to Postgres using
psql
from the HOST machine and within database container using credentials below. - Verified the value of
show listen_addresses;
is "*". - Watching the log output of Postgres does not show any messages releated to connections when attempting to login using phppgadmin, or errors.
- Provided recommended and required environment variables to the containers.
- I have tried changing the forwarded port of the database container and then changing
PHP_PG_ADMIN_SERVER_PORT
, no difference. netstat
confirms the database is listening on the right port on the host.- I have rebuilt the containers many times, including deleting Postgres' data folder.
- Just in case something was off with automatic name resolution, I tried manually substituting the docker IP address of the database container in
PHP_PG_ADMIN_SERVER_HOST
.
docker-compose.yaml
networks:
centurion:
name: centurion-net
services:
benard:
image: postgres:latest
restart: always
volumes:
- /opt/containers/benard/persist/data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=pg
- POSTGRES_USER=pg
- POSTGRES_PASSWORD=password
ports:
- "5432:5432"
networks:
- centurion
benard_ui:
depends_on:
- benard
restart: always
image: dockage/phppgadmin:latest
ports:
- "8200:80"
environment:
- PHP_PG_ADMIN_SERVER_DESC=BENARD
- PHP_PG_ADMIN_SERVER_HOST=benard
- PHP_PG_ADMIN_SERVER_PORT=5432
- PHP_PG_ADMIN_SERVER_SSL_MODE=allow
- PHP_PG_ADMIN_SERVER_DEFAULT_DB=template1
- PHP_PG_ADMIN_SERVER_PG_DUMP_PATH=/usr/bin/pg_dump
- PHP_PG_ADMIN_SERVER_PG_DUMPALL_PATH=/usr/bin/pg_dumpall
- PHP_PG_ADMIN_DEFAULT_LANG=auto
- PHP_PG_ADMIN_AUTO_COMPLETE=default on
- PHP_PG_ADMIN_EXTRA_LOGIN_SECURITY=false
- PHP_PG_ADMIN_OWNED_ONLY=false
- PHP_PG_ADMIN_SHOW_COMMENTS=true
- PHP_PG_ADMIN_SHOW_ADVANCED=false
- PHP_PG_ADMIN_SHOW_SYSTEM=false
- PHP_PG_ADMIN_MIN_PASSWORD_LENGTH=1
- PHP_PG_ADMIN_LEFT_WIDTH=200
- PHP_PG_ADMIN_THEME=default
- PHP_PG_ADMIN_SHOW_OIDS=false
- PHP_PG_ADMIN_MAX_ROWS=30
- PHP_PG_ADMIN_MAX_CHARS=50
- PHP_PG_ADMIN_USE_XHTML_STRICT=false
- PHP_PG_ADMIN_HELP_BASE=http://www.postgresql.org/docs/%s/interactive/
- PHP_PG_ADMIN_AJAX_REFRESH=3
networks:
- centurion
答案1
得分: 0
如果您使用 docker exec
进入 phppgadmin 容器并尝试使用 psql
命令连接到 PostgreSQL,您将看到以下错误消息:
psql: SCRAM authentication requires libpq version 10 or above
最初,我打算介绍如何配置较新版本的 PostgreSQL 以使用 md5 身份验证,但后来我发现这没有意义:
dockage/phppgadmin
镜像中的 phppgadmin 版本仅支持 PostgreSQL 版本 12 及以下。使用任何更新版本都会导致以下错误消息:
版本的 PostgreSQL 不受支持。请升级到版本或更高版本。
看起来该镜像在四年多前的时候进行了最后更新,因此您可能需要寻找一个更新的替代品(或者自己构建一个)。
考虑到上述限制,一个可工作的配置如下:
volumes:
postgres_data:
services:
postgres:
image: docker.io/postgres:12
volumes:
- "postgres_data:/var/lib/postgresql/data"
environment:
POSTGRES_USER: "$POSTGRES_USER"
POSTGRES_PASSWORD: "$POSTGRES_PASSWORD"
command:
- postgres
- -c
- log_connections=on
phppgadmin:
image: docker.io/dockage/phppgadmin:latest
environment:
PHP_PG_ADMIN_SERVER_DESC: postgres
PHP_PG_ADMIN_SERVER_HOST: postgres
PHP_PG_ADMIN_SERVER_PORT: "5432"
ports:
- "8000:80"
假设我有以下 .env
文件:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secret
然后我可以运行 docker-compose up
,连接到 http://localhost:8000,并使用用户名 postgres
和密码 secret
登录。
英文:
If you docker exec
into the phppgadmin container and try to connect to postgres with the psql
command, you'll see:
psql: SCRAM authentication requires libpq version 10 or above
And originally I was going to write about how to configure recent versions of Postgres to use md5 authentication instead, but then I discovered that was pointless:
The version of phppgadmin in the dockage/phppgadmin
image only supports Postgres up to version 12. Using anything more recent results in the error message:
> Version of PostgreSQL not supported. Please upgrade to version or later.
It looks like that image was last updated over four years ago, so you may want to find a more recent alternative (or build your own).
With the above limitation in mind, a working configuration looks like this:
volumes:
postgres_data:
services:
postgres:
image: docker.io/postgres:12
volumes:
- "postgres_data:/var/lib/postgresql/data"
environment:
POSTGRES_USER: "$POSTGRES_USER"
POSTGRES_PASSWORD: "$POSTGRES_PASSWORD"
command:
- postgres
- -c
- log_connections=on
phppgadmin:
image: docker.io/dockage/phppgadmin:latest
environment:
PHP_PG_ADMIN_SERVER_DESC: postgres
PHP_PG_ADMIN_SERVER_HOST: postgres
PHP_PG_ADMIN_SERVER_PORT: "5432"
ports:
- "8000:80"
Assuming that I have the following .env
file:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secret
Then I can docker-compose up
, connect to http://localhost:8000, and login as user postgres
with password secret
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论