1

Error:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL:  password authentication failed for user "username"

Hello, I am trying to run a program locally using Docker and am getting the error in the title, even though it was working before.

I've tried reinstalling Docker, re-cloning the repo, reinstalling PostgresSQL (the problem started when I installed it for the first time). From reading similar questions, I ensured that the password matches. The password is 'password' for the Docker Postgres Database and I've tried changing it but it still hasn't worked.

I'm using 'docker-compose up -d' and then running tests but I get the error in the title. I've tried running 'docker-compose down' and then redoing it, but I still get the error.

.env file:

FLASK_ENV=development
REDIS_URL=redis://localhost:6379
DATABASE_URL=postgresql+psycopg2://username:password@localhost:5432/programname
PROGRAM_API_APP_NAME=test-prod.compute.random.com

docker-compose.yml:

version: '3'

services:
  postgresql:
    image: postgres:10-alpine
    environment:
      - POSTGRES_DB=programname
      - POSTGRES_PASSWORD=password
      - POSTGRES_USER=username
    ports:
      - "5432"
  redis:
    image: redis:5.0.3
    ports:
      - "6379:6379"

(I don't have the port as 5432:5432 because it didn't work with that and I found an answer to remove the second 5432.)

James
  • 51
  • 7
  • The postgres in docker isn't at localhost, it's at the host postgresql. You must be connecting to a different instance of postgres that is running on your machine. That's likely also why you couldn't use 5432:5432 because that port was already bound. – Jeremy Jul 23 '19 at 17:46
  • Thanks for the response! I'm not very experienced with these things. How could I fix this? – James Jul 23 '19 at 17:50

1 Answers1

4

Boss helped me with this. Apparently, when I installed Postgres, it created a postgres user that had a process that was using port 5432 and even when we killed it, it automatically restarted. To solve this specific problem, we changed the docker-compose file to use port 5433 locally and 5432 in the container. Still have to find out how to get rid of the postgres user.

James
  • 51
  • 7
  • Here is how to kill the process https://stackoverflow.com/questions/42416527/postgres-app-port-in-use – James Jul 25 '19 at 17:39