Jay Jung
Jay Jung

Reputation: 1895

Docker-compose up unable to authenticate postgres user

Running docker-compose -f production.yml up will eventually return:

postgres_1      |   Connection matched pg_hba.conf line 95: "host all all all md5"
django_1        | PostgreSQL is unavailable (sleeping)...
postgres_1      | 2018-03-21 07:48:35.575 UTC [120] FATAL:  password authentication failed for user "DbUsErName"
postgres_1      | 2018-03-21 07:48:35.575 UTC [120] DETAIL:  Password does not match for user "DbUsErName".  

In my .envs/.production/.postgres I have my envs laid out in this manner:

# PostgreSQL
# ------------------------------------------------------------------------------
POSTGRES_DB=luup
POSTGRES_USER=DbUsErName
POSTGRES_PASSWORD=myVeryYLongPW

Before the error above, the terminal will also output:

celeryworker_1  | /entrypoint.sh: line 13: POSTGRES_USER: parameter not set  

However it does appear it's being set in this file within compose/production/django/entrypoint.sh:

set -o errexit
set -o pipefail
set -o nounset


cmd="$@"

if [ -z "${POSTGRES_USER}" ]; then
    # the official postgres image uses 'postgres' as default user if not set explictly.
    export POSTGRES_USER=postgres
fi
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}"

I haven't touched much postgres configs since I started the project as this is an attempt to only get it up and running on Heroku. So I haven't gone into psql.

What do I need to do to get this up and running?

Please let me know if additional information is needed.

Edit--production.yml:

version: '2'

volumes:
  postgres_data: {}
  postgres_backup: {}
  caddy: {}

services:
  django: &django
    build:
      context: .
      dockerfile: ./compose/production/django/Dockerfile
    depends_on:
      - postgres
      - redis
    env_file:
      - ./.envs/.production/.django
      - ./.envs/.production/.postgres
      - ./.envs/.production/.celery
    command: /gunicorn.sh

  postgres:
    build:
      context: .
      dockerfile: ./compose/production/postgres/Dockerfile
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - postgres_backup:/backups
    env_file:
      - ./.envs/.production/.postgres

  caddy:
    build:
      context: .
      dockerfile: ./compose/production/caddy/Dockerfile
    depends_on:
      - django
    volumes:
      - caddy:/root/.caddy
    env_file:
      - ./.envs/.production/.caddy
    ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:443:443"

  redis:
    image: redis:3.0

  celeryworker:
    <<: *django
    depends_on:
     - postgres
     - redis
    env_file:
      - ./.envs/.production/.celery
    command: /start-celeryworker.sh

  celerybeat:
    <<: *django
    depends_on:
      - postgres
      - redis
    env_file:
      - ./.envs/.production/.celery
    command: /start-celerybeat.sh

Upvotes: 0

Views: 3276

Answers (1)

Quba
Quba

Reputation: 5306

Postgres container creates a user from env variables on the first run. So in order to have it with new values (production username and password), You probably have to rebuild that.

  • docker-compose stop postgres
  • docker-compose rm postgres
  • docker-compose -f production.yml up

Upvotes: 3

Related Questions