我有一个 docker-compose 可以调出 psql 数据库,如下所示,目前我正在尝试使用 pgAdmin4 (不在 docker 容器中)连接到它并能够查看它。我在与数据库进行身份验证时遇到问题,我不明白为什么。
docker-compose
version: "3"
services:
# nginx and server also have an override, but not important for this q.
nginx:
ports:
- 1234:80
- 1235:443
server:
build: ./server
ports:
- 3001:3001 # app server port
- 9230:9230 # debugging port
env_file: .env
command: yarn dev
volumes:
# Mirror local code but not node_modules
- /server/node_modules/
- ./server:/server
database:
container_name: column-db
image: 'postgres:latest'
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres # The PostgreSQL user (useful to connect to the database)
POSTGRES_PASSWORD: root # The PostgreSQL password (useful to connect to the database)
POSTGRES_DB: postgres # The PostgreSQL default database (automatically created at first launch)
volumes:
- ./db-data/:/var/lib/postgresql/data/
networks:
app-network:
driver: bridge
我做
docker-compose up
然后检查日志,它说它已准备好连接。我转到 pgAdmin 并输入以下内容:
其中密码为
root
。然后我得到这个错误:
FATAL: password authentication failed for user "postgres"
我检查了 docker 日志,我明白了
DETAIL: Role "postgres" does not exist.
我不确定我做错了什么,根据文档,应该使用这些规范创建超级用户。我错过了什么吗?我已经用头来反对这个问题一个小时了。如有任何帮助,我们将不胜感激!
@jjanes 在评论中解决了这个问题,我使用了映射卷并且从未正确设置数据库。删除音量,我们就可以开始了。
就我而言,这是一个权限问题。
目录的所有者和组被错误更改。
我将其改回我的用户(lcompare)和组(lcompare)并且它起作用了。
sudo chown lcompare:lcompare db
对不起我的五美分。我在 docker 镜像 postgres:14.7-alpine 上遇到了同样的问题。虽然清除音量没有帮助。但我注意到 docker-compose.yaml 中用于 postgres 服务和清除卷的注释端口对我有帮助。也许是 postgres 数据库初始化逻辑的问题。
# ports:
# - 5432:5432
仅当您尝试在主机上打开端口 5432 进行内部应用程序连接时才需要这些端口,但没有必要。