-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
PostgreSQL: Document how a dependent service/container should detect when the database has started #2467
Comments
The best way for your application to know whether a dependency it relies on is up/ready for use is to query it directly, and I don't think there are really very many good shortcuts for doing so. In general, the best way to test for See https://github.com/docker-library/healthcheck/blob/40afbf64d69cf933af0da4df6383958a29113601/postgres/docker-healthcheck for an example "healthcheck" which does this from within the |
Thanks |
It looks like this can be achieved with:
|
That condition relies on a configured and working healthcheck on the container (https://docs.docker.com/reference/dockerfile/#healthcheck and/or https://docs.docker.com/reference/cli/docker/container/run/#:~:text=groups%20to%20join-,%2D%2Dhealth%2Dcmd,-Command%20to%20run), none of which is installed, enabled, or configured in this image by default. (the comment you linked to notably does not explicitly connect via TCP as noted in this thread and in that thread lower in #2391 (comment), so it will not detect that PostgreSQL is ready but rather will mis-detect the initial setup instance as healthy) |
When using the provided |
Sorry, I retract most of my previous comment. I can't remember the details, but I was confused because basically I was just not using the right command for the changes to take effect. The intervals are set in the compose file, it's just that depending on which command you use, you could stick with the values from earlier versions of your compose file. |
Yes, thanks anyway but by "best" I don't just mean reliable, I also mean efficient. I.e. a method which uses a pushed signal rather than polling. |
Yeah, that would be nice, but I don't think Docker supports anything like sd_notify, so we don't have a mechanism for the container to notify outwards except polling / listening port state changes. |
Thanks Tianon, I'm afraid you're right. So yes, this seems to be about:
|
The
postgres
images provide an RDBMS which is usually a dependency of other services. The Composedepends_on
attribute allows to express that, but itsconditions
attribute defaults toservice_started
, which does not work properly (the dependency is satisfied too early).Lots of webpages deal with that issue, such as the
docker-compose-healthcheck
project, usually suggesting theservice_healthy
condition instead. It would be great to either provide a proper/reliable way for PostgreSQL to signal dependents that it is actually started, or at least mitigate by documenting the best way to workaround.The text was updated successfully, but these errors were encountered: