Error password authentication failed for user "postgres"

I’m trying to connect to a Postgres image running on a docker container and I’m having trouble connecting to it.

version: '3.4'
services:
  postgres:
    image: postgres:alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: postgres
    logging:
      options:
        max-size: 10m
        max-file: "3"
    ports:
      - "5432:5432"

I know the container is successfully running on port 5432:

CONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS         PORTS                                       NAMES
a553b2135fcf   postgres:alpine   "docker-entrypoint.s…"   3 seconds ago   Up 2 seconds   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   postgres

I tried to connect two ways.

PgAdmin

PgAdmin: General 
Name: postgres

PgAdmin: Connection
Hostname/address: 127.0.0.1
Port: 5432
Maintenance database: postgres
Username: postgres
Password: password

I received the following error:

Unable to connect to server:
FATAL: password authentication failed for user "postgres" 

Visual Studio Code

Hostname:  127.0.0.1
Postgres User: postgres
Postgres Password; password
Port number: 5432
Standard Connection 

I get the same error:

 password authentication failed for user "postgres"

Can you connect from the container using the same username and password?

Envs are used by postgres initdb to create your postgresql instance. If you changed yours envs after first execution, you need to delete the postgres container to force a recreation using new envs. If you have defined a volume, you will also need to remove it.

1 Like

Hi there!
Can the problem be the semi-colon after the password, on the VS Codedile:

Visual Studio Code

Hostname:  127.0.0.1
Postgres User: postgres
**Postgres Password; password**
Port number: 5432
Standard Connection 

Hi, I am going through the same situation, from the container I can enter without problems, but when I do a get from my api it gives me that error. How did you fix it?

it will work if you change the local port attached to docker port
something like 1234:5432
i think its because postgressql is installed in the system and its listening to teh port 5432 and the port in docker is colliding with it.
remove postgres from the system