Home > Software design >  How does Postgresql inside Docker work? psql: FATAL: password authentication failed for user xy
How does Postgresql inside Docker work? psql: FATAL: password authentication failed for user xy

Time:04-30

I created my app with .yml

services:

  db:
    image: postgres:11-alpine
    environment:
      POSTGRES_DB: wiki
      POSTGRES_PASSWORD: quantoxrocks
      POSTGRES_USER: wikijs
    logging:
      driver: "none"
    restart: unless-stopped
    volumes:
      - db-data:/var/lib/postgresql/data

  wiki:
    image: ghcr.io/requarks/wiki:2
    depends_on:
      - db
    environment:
      DB_TYPE: postgres
      DB_HOST: db
      DB_PORT: 5432
      DB_USER: wikijs
      DB_PASS: quantoxrocks
      DB_NAME: wiki
    restart: unless-stopped
    ports:
      - "3000:3000"
    
  webserver:
    image: nginx:alpine
    restart: unless-stopped
    tty: true
    ports:
       - "443:443"
       - "80:80"            
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./ssl:/etc/nginx/ssl        
volumes:
  db-data:

I logged in my db container and want to create database. I have tried at least 10 times and I am sure that password is from the above docker-compose.yml file. It does not work.

docker exec -it wiki_db_1 sh

Next

psql -h wiki_db_1 -U wikijs
Password for user wikijs: 
psql: FATAL:  password authentication failed for user "wikijs"

Why? How can I check any further logs?

CodePudding user response:

The environment variables for Postgres are only used if there is no database present already when the container starts.

You have a volume mapping of /var/lib/postgresql/data and it's likely that you already have a database there, which was created with different values from the environment variable values.

If you don't have any important data in the existing database, you can delete the volume and Postgres will create a new database with the correct username/password.

CodePudding user response:

check your volumes: db-data: bit.

  • Related