Docker django postgres role does not exist

I've been having this error where docker continuously tells me that there isn't a user postgres. After searching around for quite some time, I've come to understand adding

environment:
      - POSTGRES_DB=iku
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=password

This creates a user admin and not the default postgres. This is the error I'm getting

src-postgres-1  | 2022-08-26 18:03:00.136 UTC [207] DETAIL:  Role "postgres" does not exist.
src-postgres-1  |   Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"

I do not face this error when I port forward to my machine. That is after adding this

ports:
      - "5432:5432"

If I do remove the above code, everything works fine. But I cannot connect PGAdmin to the Postgres running on docker as the port is not exposed to the outside. This port tells me role postgres does not exist. Any help would be appreciated! This is my docker-compose file

version: "3.9"

services:
  postgres:
    image: postgres:14.5
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=custom
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=password
    ports:
      - "5432:5432"
  redis:
    restart: always
    image: redis:latest
    ports:
      - "6379:6379"
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - postgres
      - redis

I thought I might be having a local postgres service running, I've checked it. I do not have a local postgres running on my Ubuntu machine. I've even uninstalled postgres to be sure.

Back to Top