password authentication failed for user while connecting postgres from local machine to docker

581 views Asked by At

I'm using docker container to connect postgres connection from my local machine to docker to import open street map data. But I'm getting authentication failed for user.

docker run --name "postgis" -p 5432:5432 -d -t kartoza/postgis:11.5-2.8

my pg_hba.conf file is

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             172.17.0.1/16            md5
host    all             all             0.0.0.0/0            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host    replication     all             127.0.0.1/32            md5
host    replication     all             172.17.0.1/16            md5
host    replication     all             ::1/128                 md5

I have changed md5 to trust also but still I'm facing below issue.

2020-10-14 04:56:53.055 UTC [166] postgres@gis FATAL: password authentication failed for user "postgres"

2020-10-14 04:56:53.055 UTC [166] postgres@gis DETAIL: User "postgres" has no password assigned.

Connection matched pg_hba.conf line 100: "host all all 172.0.0.0/8 md5"

and my postgres version is 11.9 and client is 11.8 and IP is "IPv4Address": "172.17.0.2/16"

How can I resolve Please suggest me

1

There are 1 answers

0
newbie On

Initially I used localhost:5432,127.0.0.1:5432 and 172.17.0.1:5432 in db connection string that causes this issue.

After using below host address in connection string my issue resolved

host.docker.internal:5432

postgres://db_user:[email protected]:5432/db