'Postgres and Docker Compose; password authentication fails and role 'postgres' does not exist. Cannot connect from pgAdmin4

I have a docker-compose that brings up the psql database as below, currently I'm trying to connect to it with pgAdmin4 (not in a docker container) and be able to view it. I've been having trouble authenticating with the DB and I don't understand why.

docker-compose

version: "3"

services:
  # nginx and server also have an override, but not important for this q.
  nginx:
    ports:
      - 1234:80
      - 1235:443
  server:
    build: ./server
    ports:
      - 3001:3001 # app server port
      - 9230:9230 # debugging port
    env_file: .env
    command: yarn dev
    volumes:
      # Mirror local code but not node_modules
      - /server/node_modules/
      - ./server:/server
  
  database:
    container_name: column-db
    image: 'postgres:latest'
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres # The PostgreSQL user (useful to connect to the database)
      POSTGRES_PASSWORD: root # The PostgreSQL password (useful to connect to the database)
      POSTGRES_DB: postgres # The PostgreSQL default database (automatically created at first launch)
    volumes:
      - ./db-data/:/var/lib/postgresql/data/

networks:
  app-network:
    driver: bridge

I do docker-compose up then check the logs, and it says that it is ready for connections. I go to pgAdmin and enter the following: first screen

second screen

where password is root. I then get this error:

FATAL:  password authentication failed for user "postgres"

I check the docker logs and I see

DETAIL:  Role "postgres" does not exist.

I'm not sure what I'm doing wrong, according to the docs the super user should be created with those specifications. Am I missing something? Been banging my head against this for an hour now. Any help is appreciated!



Solution 1:[1]

@jjanes solved it in a comment, I had used a mapped volume and never properly set up the db. Removed the volume and we're good to go.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 OmegaNalphA