我正在使用以下图片 https://hub.docker.com/r/dpage/pgadmin4/在 Ubuntu 18-04 上设置 pgAdmin4。
我已经安装了一个包含 pgpass
文件的卷(对于容器内的 pgadmin
用户来说也是 chmod
),如您所见在我的撰写文件中:
version: '3.8'
services:
pgadmin4:
image: dpage/pgadmin4
container_name: pgadmin4
environment:
- PGADMIN_DEFAULT_EMAIL=me@localhost
- PGADMIN_DEFAULT_PASSWORD=******************
- PGADMIN_LISTEN_PORT=5050
- PGADMIN_SERVER_JSON_FILE=servers.json
volumes:
- ./config/servers.json:/pgadmin4/servers.json # <-- this file is well taken into account
- ./config/pgpass:/pgpass # <- there is no way to find this one on the other hand
ports:
- "5000:5000"
restart: unless-stopped
network_mode: host
但是当我右键单击服务器并检查其高级属性时,pgadmin 网页似乎无法识别它:
如果我在顶部绿色框中手动指定 /pgpass
,其中图像中只有一条斜杠,它会显示:
但如果我登录容器,我实际上可以列出该文件:
/ $ ls -larth /pgpass
-rw------- 1 pgadmin pgadmin 574 Mar 10 22:37 /pgpass
我做错了什么?
如何让应用程序识别 pgpass
文件?
最佳答案
我根据以下见解得到了它。
在 servers.json 中指定时:
"PassFile": "/pgpass"
表示路径中的/
开始于用户的存储目录,即
pattern:
/var/lib/pgadmin/storage/<USERNAME>_<DOMAIN>/
example:
/var/lib/pgadmin/storage/postgres_acme.com/
这是一个工作示例,它可以将所有内容复制到正确的位置并正确设置权限。
pgadmin:
image: dpage/pgadmin4
restart: unless-stopped
environment:
PGADMIN_DEFAULT_EMAIL: postgres@acme.com
PGADMIN_DEFAULT_PASSWORD: postgres
PGADMIN_LISTEN_ADDRESS: '0.0.0.0'
PGADMIN_LISTEN_PORT: 5050
tty: true
ports:
- 5050:5050
volumes:
- ~/data/pgadmin_data:/var/lib/pgadmin
- ./local-cloud/servers.json:/pgadmin4/servers.json # preconfigured servers/connections
- ./local-cloud/pgpass:/pgadmin4/pgpass # passwords for the connections in this file
entrypoint: >
/bin/sh -c "
mkdir -m 700 /var/lib/pgadmin/storage/postgres_acme.com;
chown -R pgadmin:pgadmin /var/lib/pgadmin/storage/postgres_acme.com;
cp -prv /pgadmin4/pgpass /var/lib/pgadmin/storage/postgres_acme.com/;
chmod 600 /var/lib/pgadmin/storage/postgres_acme.com/pgpass;
/entrypoint.sh
"
关于docker - 当此文件作为卷安装时,pgadmin4 docker 容器中的 pgpass 文件在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66578506/