13

On EC2 linux server create by docker-machine, when I launch docker postgres:10.6 by docker-compose up, I have these loop errors :

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

I don't have these errors if I start container manually => docker run -e POSTGRES_PASSWORD=myPassword postgres:10.6

I don't have these errors in my local docker.

My docker-compose :

db:
  container_name: postgres
  image: postgres:10.6
  restart: always
  environment:
    POSTGRES_PASSWORD: myPassword
  ports:
    - "5432:5432"

Does anyone know how to fix this?

0

2 Answers 2

20

It might be because the volume (or bind mount directory) being already initialized after your first start. The postgres user, and database creation only happens on the first start (ie, /var/lib/postgresql/data must not already contain database files). Try to run:

  • docker-compose rm -fv postgres to delete any containers or volumes (in particular).
  • docker-compose up -d to start your container.
Sign up to request clarification or add additional context in comments.

4 Comments

Use docker-compose rm -sfv postgres instead, if you are not sure whether the container is running or not
I had to run docker volume ls to find the name of the volume, and then docker volume rm <volume_name>. Then I could reinitialize the postgres volume
thanks a lot. It helps. In my case, when I create docker image at the first time I run with sudo. I advise others also don't repeat my mistake
I had to make sure no app was still referencing the db with the old credentials..
0

Sorry for that I have the answer to my question, it's not a bug I just have something that tries to connect permanently to postgres (through port 5432 which is open) ...

After search, I think it's an attempt at hacking because incoming connections never come from the same IP

connection received: host=45.120.120.149.81 port=47118
connection received: host=210.4.125.252 port=44774
connection received: host=82.223.55.254 port=36320

etc....

1 Comment

If you previously had PgAdmin setup with Postgres w/o a password, and then tried setting one via POSTGRES_PASSWORD, you will also see repeating login failures just like this.

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.