Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
psql -h localhost fails in init script #474
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:
I tried this on windows and linux and with and without the
Does a workaround exist for this?
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
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:
- postgresql://postgres@localhost:5432/postgres + postgresql://postgres@:5432/postgres
#!/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;'