Docker Django Postgres FATAL: password authentication failed for user "postgres

I am dockerizing my Django app. My configs are the following:

csgo.env

POSTGRES_NAME='postgres'
POSTGRES_USER='postgres'
POSTGRES_PASSWORD='postgres'
POSTGRES_HOST='postgres_db'
POSTGRES_PORT='5432'

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.getenv('POSTGRES_NAME', 'postgres'),
        'USER': os.getenv('POSTGRES_USER', 'postgres'),
        'PASSWORD': os.getenv('POSTGRES_PASSWORD', 'postgres'),
        'HOST': os.getenv('POSTGRES_HOST', 'postgres_db'),
        'PORT': os.getenv('POSTGRES_PORT', '5432'),
    }
}

docker-compose.yml

version: '3'

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    env_file:
      - csgo.env
    ports:
      - '8000:8000'
    volumes:
      - .:/code
    depends_on:
      - postgres_db

  postgres_db:
    image: postgres:13
    restart: always
    ports:
      - '5432:5432'
    env_file:
      - csgo.env
    environment:
      - POSTGRES_NAME='postgres'
      - POSTGRES_USER='postgres'
      - POSTGRES_PASSWORD='postgres'
      - POSTGRES_HOST='postgres_db'
      - POSTGRES_PORT='5432'

When I run docker-compose up, I get the typical auth error django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres" and I am really stressed of it. I have been looking for a typo a day long and haven't figured it out. Please help me to find the missing piece of code or the typo!

Note: I know that this kind of questions are overflowed on the Internet. My post is about finding a typo or a mechanical mistake by me. Thanks for understanding and not assigning the post as a duplicate one!

you should set database name in your environment variables:

POSTGRES_DB='postgres'
Back to Top