Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth Error With Postgre Container Using Docker Compose #19865

Closed
1 task done
berkesayin opened this issue Apr 24, 2024 · 2 comments
Closed
1 task done

Auth Error With Postgre Container Using Docker Compose #19865

berkesayin opened this issue Apr 24, 2024 · 2 comments
Labels
area/get-started Relates to get started and onboarding docs status/triage Needs triage

Comments

@berkesayin
Copy link
Contributor

berkesayin commented Apr 24, 2024

Is this a docs issue?

  • My issue is about the documentation content or website

Type of issue

Information is incorrect

Description

When attempting to run a Docker Compose setup with todo-app server and postgres containers, authentication failures happens for PostgreSql container. (Docker docs: using containers for Node.js development)

img3

authentication error:

2024-04-24 16:25:40.510 UTC [27] FATAL: password authentication failed for user "postgres"

Environment

  • Operating System: MacOS (M1 - Apple Silicon - ARM64)
  • Docker version 26.0.0
  • Docker Compose version v2.26.1-desktop.1

Location

https://docs.docker.com/language/nodejs/develop/

Suggestion

Default environment setup for db service

environment:
  - POSTGRES_DB=example
  - POSTGRES_PASSWORD_FILE=/run/secrets/db-password

This causes authentication error below:
2024-04-24 16:25:40.510 UTC [27] FATAL: password authentication failed for user "postgres"

To resolve this issue, modified the db service environments setup at Docker Compose configuration to adjust the PostgreSQL container's authentication method:

environment:
  - POSTGRES_DB=example
  - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
  - POSTGRES_HOST_AUTH_METHOD=md5 #added 
  - PGDATA=/var/lib/postgresql/data/pgdata #added 

With these change, the PostgreSQL container switches to using the "md5" authentication method, which resolves the authentication failure encountered with the default method.

img2

PostgreSQL Authentication Methods

I'm adding a PR regarding this issue. #19866

@berkesayin berkesayin added the status/triage Needs triage label Apr 24, 2024
@craig-osterhout craig-osterhout added the area/get-started Relates to get started and onboarding docs label Apr 25, 2024
@craig-osterhout
Copy link
Contributor

Thanks for sharing the issue.
I was able to reproduce the error by adding a newline character in the db/password.txt file. Your suggested fix did not resolve the issue caused by the newline character, so your issue is most likely slightly different, but probably associated with the contents of the password.txt file.

You can check your password.txt file for any hidden characters and try a more simple password. Note that you would need to delete the volume to reinitialize.

This section is very error-prone, and does need to be updated.

@berkesayin
Copy link
Contributor Author

Thanks for taking the time to reply. I really like open-source docs and projects of docker and the support provided by the docker community.

The problem I mentioned here and your answer might be for different subjects. I tried to explain that if someone skips creating the password.txt file and first runs docker compose up, the database will be initialized without password and this will cause the auth error after creating password and running docker compose up again.

The authentication error: 2024-04-24 16:25:40.510 UTC [27] FATAL: password authentication failed for user "postgres".

I updated my compose.yaml file for db service as I explained in the beginning of the issue. And this solved my auth problem.

Thanks again for your answer. @craig-osterhout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/get-started Relates to get started and onboarding docs status/triage Needs triage
Projects
None yet
Development

No branches or pull requests

2 participants