Edouard
Edouard

Reputation: 131

password authentication failed for user "postgres" with docker-compose up on EC2

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?

Upvotes: 13

Views: 18931

Answers (2)

Edouard
Edouard

Reputation: 131

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....

Upvotes: 0

Akshay Shah
Akshay Shah

Reputation: 734

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.

Upvotes: 20

Related Questions