docker-nginx-postgres-django-example
docker-nginx-postgres-django-example copied to clipboard
Failed to do postgresql migration with authentication error
The problem:
Hi, I have a project ongoing and found your docker tutorial [Docker Compose with NginX, Django, Gunicorn and multiple Postgres databases](https://pawamoy.github.io/posts/docker-compo
se-django-postgres-nginx/) pretty helpful and had followed along the tutorial.
Unfortunately, I was stuck on the part that I can't migrate to
postgresql as the following command sugguest:
docker-compose run --rm djangoapp /bin/bash -c "cd hello; ./manage.py migrate"
After executing the command above, i got error message complain about
django.db.utils.OperationalError: FATAL: password authentication failed for user "database1_role"
But I could still successfully build the dockerfile
How I try to solve it:
I try to run postgresql server but it complains about the host/local connection:
➜ test_docker git:(master) ✗ psql psql: error: could not connect to server: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I look it up on stackoverflow and try to brew restart the service or rm postmaster.pid....But it does not work.
Also I try to investigate the config file pg_hba.conf which defines who gets to log in what database at /usr/local/var/postgres/pg_hba.conf.
81| # TYPE DATABASE USER ADDRESS METHOD 82| 83| # "local" is for Unix domain socket connections only 84| local all all trust 85| # IPv4 local connections: 86| host all all 127.0.0.1/32 trust 87| # IPv6 local connections: 88| host all all ::1/128 trust 89| # Allow replication connections from localhost, by a user with the 90| # replication privilege. 91| local replication all trust 92| host replication all 127.0.0.1/32 trust 93| host replication all ::1/128 trust 94| host all all 127.0.0.1/5432 trust
Still no luck. Wander anyone has some suggestions to solve the problem? Thanks!
Hi!
Did you try to run the command docker-compose run --rm djangoapp /bin/bash -c "cd hello; ./manage.py migrate" twice? The first time it usually fails because the database wasn't ready before the Django app is started.
Hi!
Did you try to run the command
docker-compose run --rm djangoapp /bin/bash -c "cd hello; ./manage.py migrate"twice? The first time it usually fails because the database wasn't ready before the Django app is started.
Thanks for the reply, I tried run the command, it did work though.
And I checked docker stats, the django app get started fine before run the migration command:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
fbb0d3eb3a04 test_docker_djangoapp_1 0.01% 42.8MiB / 1.944GiB 2.15% 1.68kB / 0B 0B / 0B 2
e9e4bdb8819a test_docker_nginx_1 0.00% 2.422MiB / 1.944GiB 0.12% 1.24kB / 0B 0B / 0B 2
db1664eeee9b test_docker_database1_1 0.00% 9.621MiB / 1.944GiB 0.48% 6.06kB / 3.43kB 0B / 0B 7
Tune Authentication Options through pg_hba.conf
I wonder the problem probably resulted in faulty local config of pg_hba.conf. Did you tune it somehow for the newly create database, as 'database1' in your tutorial? Thanks :)
reference:
- https://stackoverflow.com/questions/12472988/postgresql-error-could-not-connect-to-server-no-such-file-or-directory
- Configure PostgreSQL
- Unable to change PostgreSQL admin
Update
I reinstall the postgresql and have no connection error now. I'll reconfig Authentication Options through pg_hba.conf later.
I wonder the problem probably resulted in faulty local config of pg_hba.conf. Did you tune it somehow for the newly create database, as 'database1' in your tutorial?
Nope, I didn't touch pg_hba.conf at all.
So, I'm not sure to understand, is your issue fixed?