how do I connect the postgres db in docker-compose.yml without the password
it ends up giving an error like
worker-1 | Waiting for db
db-1 | 2025-02-17 01:44:57.551 UTC [43] FATAL: password authentication failed for user "postgres"
db-1 | 2025-02-17 01:44:57.551 UTC [43] DETAIL: Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
result-1 | Waiting for db
context : Demo - Example Voting Application with Docker Compose
According to the image’s docs, setting this in environment
will work:
POSTGRES_HOST_AUTH_METHOD: trust
You might be able to get a password to work with some other setting of POSTGRES_HOST_AUTH_METHOD; read the docs for more information.
1 Like
yeah, I did do that and was still not running,
had to remove all of the previous creations by “docker compose”
also, I found there are 2 ways to give environment variables in docker compose:
- which you mentioned
environment:
POSTGRES_HOST_AUTH_METHOD: trust
- directly passing it with ‘=’ sign
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
which one of these is a better way to do things going forward??
is is the key:value type or the variable=value type
The docker-compose file reference says either syntax can be used. As to why it isn’t working for you – look in the logs and see if they are more informative. But the docs make it clear that if you specify POSTGRES_USER and POSTGRES_HOST_AUTH_METHOD, that you should be able to access the DB w/o specifying a password.