Docker Community Forums

Share and learn in the Docker community.

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?