postgresql - 尝试 phppgadmin docker 容器查看主机上的 postgres 数据库:它说登录失败
问题描述
我想用 phppgadmin docker 容器查看主机 postgresql
我的主机是archlinux,上面运行着postgresql 服务器。
我有 /var/lib/postgres/data/postgresql.conf
listen_addresses = "*"
和
/var/lib/postgres/data/pg_hba.conf
host all all 172.17.0.0/16 password
我想查看 postgresql 表。所以我使用 phppgadmin docker 和以下命令
docker run --name='phppgadmin' --rm \
--publish=8888:80 \
-e PHP_PG_ADMIN_SERVER_HOST="127.0.0.1" \
dockage/phppgadmin:latest
现在我可以从127.0.0.1:8888/phppgadmin
但是当我尝试登录时它说login failed
我的主机上有一个 django 项目,使用主机 postgresql。这适用于设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': ‘<db_name>’,
'USER': '<db_username>',
'PASSWORD': '<password>',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
还有我在主机上的 netstat 输出
$ netstat -nrv
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlp3s0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-1c7e732767f4
172.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-17604ffc4858
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlp3s0
在我的码头集装箱上
$ netstat -nrv
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
解决方案
从netstat -nrv
我的 phppgadmin docker 容器
$ netstat -nrv
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
所以主机的ip地址是172.17.0.1
更改PHP_PG_ADMIN_SERVER_HOST="127.0.0.1"
为PHP_PG_ADMIN_SERVER_HOST="172.17.0.1"
docker run --name='phppgadmin' --rm \
--publish=8888:80 \
-e PHP_PG_ADMIN_SERVER_HOST="172.17.0.1" \
dockage/phppgadmin:latest
和:
我有 /var/lib/postgres/data/postgresql.conf
listen_addresses = "localhost,127.0.0.1,172.17.0.1"
和
/var/lib/postgres/data/pg_hba.conf
host all all 172.17.0.0/16 md5
127.0.0.1:8888/phppgadmin
使用非超级用户打开并登录
对于超级用户,它仍然无法正常工作。