-
Notifications
You must be signed in to change notification settings - Fork 1.2k
psql -h localhost fails in init script #474
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
Comments
A recent change to the I too ran into this limitation when trying to run db migrations (via flyway) during this init context: https://stackoverflow.com/questions/51699847/flyway-unable-to-connect-to-postgres-container-within-docker-entrypoint-initdb-d I would also appreciate a suggested workaround and would suggest the documentation be updated to clearly state the limitations of |
This was also discussed a little over in #441. I think the best workaround (short of using the unix socket instead) is suggested in #440 (comment):
|
Thanks for mentioning that. If desired I can create a PR to add this workaround to the documentation. |
I'm a bit wary of actively documenting the workaround since I think that would provide users with a false sense of the level to which it's supported. For example, if we could find a way to appropriately provide the arguments to the image (https://github.com/docker-library/docs/tree/57a71eed9a741dd9a64b9a439d2664b896bff87d/postgres#database-configuration) on to |
Edit: I see that the crucial problem here is that you can't modify this third party script. Perhaps you could send a PR to have it fixed? 🤔 For what it's worth, I ran into a similar problem where I wasn't able to connect to the postgres instance whilst using a connection string that set the host part to localhost. Based on the docs I dropped the explicit host part:
Therefore: - postgresql://postgres@localhost:5432/postgres
+ postgresql://postgres@:5432/postgres The #!/bin/bash
psql postgresql://postgres@:5432/postgres -c 'select 1;' Or using your existing format, just don't specify the host part and it should work: #!/bin/bash
psql -p 5432 -U postgres -d postgres -c 'select 1;' |
Thanks for the detailed examples, @AlanFoster 👍 I've opened docker-library/docs#1298 to add a blurb to the documentation about this. |
The following workaround without restarting postgres also works for me in a postgres:17-alpine3.20 based Dockerfile:
|
psql -h localhost fails in init scripts. I encountered this problem while running a third party script I can not change.
Simple Dockerfile to reproduce:
init.sh:
Output:
I tried this on windows and linux and with and without the
chmod
line. The crucial part in the psql command is the-h localhost
option. All other options can be removed and the error still occurs, but if the-h
is removed everything works fine.Does a workaround exist for this?
The text was updated successfully, but these errors were encountered: