Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dockerized PostgreSQL: FATAL: password authentication failed for user "postgres

I have a dockerized PSQL instance and a dockerized app that connects to it. I am getting an incorrect password error trying to connect despite never setting one. Default of postgres doesn’t work.

compose.yml

services:
  psql:
    build: database/.
    env_file: vars.env
    ports:
      - "5432:5432"
  reader:
    build: reader/.
    env_file: vars.env
    restart: always

reader.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import psycopg2

connection = psycopg2.connect(
    database="postgres",
    user="postgres",
    password="postgres",
    host="psql",
    port=5432)

cursor = connection.cursor()

Error

psycopg2.OperationalError: connection to server at "psql" (172.29.0.3), port 5432 failed: FATAL:  password authentication failed for user "postgres"

What could this password be? Or how is it set. I thought no default user or pass was set.

>Solution :

You have to make sure the vars.env file has these:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

For trouble shooting I’d remove the vars.env and uses a direct environment variable as the docs suggests, to see if it works:

  psql:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: postgres

From docs:

The PostgreSQL image uses several environment variables which are easy
to miss. The only variable required is POSTGRES_PASSWORD, the rest are
optional.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading