Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 341
Edouard Avatar asked Apr 13 '19 16:04

Edouard


1 Answers

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.
like image 122
Akshay Shah Avatar answered Oct 31 '22 15:10

Akshay Shah