连接到Postgres Docker服务器-身份验证失败 [英] Connecting to Postgres Docker server - authentication failed

查看:92
本文介绍了连接到Postgres Docker服务器-身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个PostgreSQL容器,可以成功与Adminer连接,但是在尝试使用相同的凭据通过诸如DBeaver之类的连接时,出现了身份验证错误.

I have a PostgreSQL container set up that I can successfully connect to with Adminer but I'm getting an authentication error when trying to connect via something like DBeaver using the same credentials.

我尝试在Dockerfile中公开端口5432,并且可以在Windows的Docker上看到端口已正确绑定.我猜是因为这是身份验证错误,所以问题不是不是服务器可见,而是用户名或密码?

I have tried exposing port 5432 in the Dockerfile and can see on Windows for docker the port being correctly binded. I'm guessing that because it is an authentication error that the issue isn't that the server can not be seen but with the username or password?

Docker Compose文件和Dockerfile看起来像这样.

Docker Compose file and Dockerfile look like this.

version: "3.7"

services:

  db:
    build: ./postgresql
    image: postgresql
    container_name: postgresql
    restart: always
    environment:
      - POSTGRES_DB=trac
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=1234
    ports:
      - 5432:5432

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

  nginx:
    build: ./nginx
    image: nginx_db
    container_name: nginx_db
    restart: always
    ports:
      - "8004:8004"
      - "8005:8005"

Dockerfile :(稍后将使用Dockerfile复制ssl证书和密钥)

Dockerfile: (Dockerfile will later be used to copy ssl certs and keys)

FROM postgres:9.6

EXPOSE 5432

想知道我是否还需要做一些其他事情,以使其能够通过其他实用程序来工作?

Wondering if there is something else I should be doing to enable this to work via some other utility?

任何帮助都会很棒.

谢谢.

更新:

试图通过postgresql容器172.28.0.3的IP访问数据库,但是连接超时,这表明PostgreSQL正确地侦听了0.0.0.0:5432,并且由于某种原因,用户和密码甚至在Docker之外也不可用.从主机使用本地主机.

Tried accessing the database through the IP of the postgresql container 172.28.0.3 but the connection times out which suggests that PostgreSQL is correctly listening on 0.0.0.0:5432 and for some reason the user and password are not usable outside of Docker even from the host machine using localhost.

推荐答案

检查Postgres数据文件夹中的pg_hba.conf文件.默认配置是您只能从localhost(我假设管理员正在这样做)登录,而不能从外部IP登录.

Check your pg_hba.conf file in the Postgres data folder. The default configuration is that you can only login from localhost (which I assume Adminer is doing) but not from external IPs.

为了允许通过密码验证从所有外部地址访问,请将以下行添加到pg_hba.conf中:

In order to allow access from all external addresses vi password authentication, add the following line to your pg_hba.conf:

host    all             all            *            md5

然后,您只要暴露端口(5432),就可以从外部连接到在docker容器中运行的postgres数据库

Then you can connect to your postgres DB running in the docker container from outside, given you expose the Port (5432)

这篇关于连接到Postgres Docker服务器-身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆