0

I am trying to have a nestjs app with a psql database dockerized. I have a docker-compose.yml:

# docker-compose.yml

version: '3.8'
services:
  
  postgres:
    image: postgres:13
    container_name: postgres_albert
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - '5432:5432'

volumes:
  postgres:
    name: volume-uni

Then I access the container:

docker exec -it 36cf6358a019 bash

And try to use psql:

psql -U postgres

I get following error:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "postgres" does not exist

I don't understand, postgres is the official user and is there when installation. I used the official image without docker-compose with the postgres user and it worked. I tried also changing users but no success

1 Answer 1

1

I finally fix it by adding the POSTGRES_DB env var in the environment section of the docker-compose.yml. In the documentation is explained that if data folder is populated, it takes some values. Like the db name is the user etc.

https://hub.docker.com/_/postgres

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.