2

containerizing a django app built with the pydanny cookiecutter for deployment to an EC2 instance. the docker_compose.yml is pretty straigtforward:

version: '2'

volumes:
  postgres_data: {}
  postgres_backup: {}

services:
  postgres:
    build: ./compose/postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - postgres_backup:/backups
    env_file: .env

  ....

nothing exotic in the dockefile; just pointers to backup and restore scripts and commands to make them executable:

FROM postgres:9.4

# add backup scripts
ADD backup.sh /usr/local/bin/backup
ADD restore.sh /usr/local/bin/restore
ADD list-backups.sh /usr/local/bin/list-backups

# make them executable
RUN chmod +x /usr/local/bin/restore
RUN chmod +x /usr/local/bin/list-backups
RUN chmod +x /usr/local/bin/backup

I've tried several variations on my db env variables, the latest of which looks like:

# PostgreSQL
POSTGRES_PASSWORD='postgrespass'
POSTGRES_USER='postgres'

the container builds and initializes without problem on:

docker-compose build postgres
docker-compose up -d

but when I try to make and migrate initial data to the db with:

docker-compose run django /usr/local/bin/python manage.py makemigrations

the db is unresponsive – "Postgres is unavailable - sleeping" and docker logs db returns:

DETAIL:  Connection matched pg_hba.conf line 95: "host all all all md5"
FATAL:  password authentication failed for user "'postgres'"

obviously I have some permission issues, but I'm not quite sure how to address them. My containers are running on an Ubuntu 16.04 AMI.

1 Answer 1

1

You can go to psql console and change the password for user postgres by typing following commands in your terminal

sudo -u postgres psql
postgres=# \password
Enter new password:
Enter it again:
postgres=#

Or To reset the password if you have forgotten:

ALTER USER "user_name" WITH PASSWORD 'new_password';
Sign up to request clarification or add additional context in comments.

2 Comments

You'd have to reach the remote instance with something like "psql -h 68.152.13.25 -p 5432 -U postgres --password" the problem with that is you just generate the same authentication error.
For password less login: sudo -u user_name psql db_name @kjarsenal

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.