-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
How to determine when new container is truly "ready" #146
Comments
I have done this:
and it seems to work, but I am still learning... |
Hi @spmacdonald, Here's the first time:
Then it runs its entrypoints, e.g. here is an example if adding postgis:
And then the restart:
And only now is it truly ready. If you kicked off a seeding/provisioning script once you saw PG "ready" the first time, you're likely to hit a failure when it restarts. I think all containers need to have a deterministic way to indicate when they're actually-truly "won't restart on you" ready without resorting to sleep timers. |
@rarkins What is the |
@md5 sorry, $PSQL is just an alias defined earlier in my file:
I am using host networking in docker, which might explain the difference? |
@rarkins You're going to have a hard time with a lot of assumptions in various Docker images if you're using host networking. |
The way the container is designed is that when it is listening on the network port via its non-loopback interface, it is ready to accept connections. Accepting connections on the loopback connection is for the scripts in |
The best way to wait for your container to be up and ready is this:
That's what we're using at Gemnasium, it avoid the "double start" issue. |
We do
|
improved version of @gravis's solution
it works even if password is required Update as noted by @enumag if you use network, then you need to add
|
@gravis @yelizariev Thank you for your solutions! |
Is the
|
As @rarkins I've struggled with the server restart too.
|
The simplest solution for me was watching the logs for |
thanks for the solution @gravis |
I tried to use the solution posted by @gravis and later improved by @yelizariev. In my case there was one more problem:
I found a fix here. I just had to add Here is the final version:
|
This should be solved if #282 is implemented, right? |
The problem is that you can't use healthcheck when using docker-compose.yml version 3 since |
As explained in this comment, solutions that merely check for connectivity (using psql or pg_isready or anything else) will not work in the general case with this image since it does a postgres restart after the initial setup (if you are mounting an existing database you're fine though).
|
@mausch Unfortunately your solution is can't be used it from inside of another container - which is what you want most of the time. Any tips for that situation? |
For future google hits: I'm using |
If using docker version 2.1
and then
|
@enumag The other solutions aren't effective because my docker image, the For those of us whose Postgres image needs to start Have not tested this on platform besides Linux, or with a goal other than 2.
|
Use this: |
As noted back in #146 (comment), the best way to test if the container is "ready" is to connect to it using its external IP address (it does not listen externally until the initialization process is fully complete). In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow. |
This approach makes sense for us for now. We implemented a similar mechanism with noedjs/knex and it fixed our docker-based CICD test runs. Perhaps at some future time we will look into the pgsql restart itself. |
Need some hints for monitoring image from: docker-library/postgres#146 (comment)
Need some hints for monitoring image from: docker-library/postgres#146 (comment)
Need some hints for monitoring image from: docker-library/postgres#146 (comment)
Need some hints for monitoring image from: docker-library/postgres#146 (comment)
This PR fixes an issue with our Docker Postgres connection where we sometimes connect before Postgres is fully up, see [1] for more details. [1] docker-library/postgres#146
This PR fixes an issue with our Docker Postgres connection where we sometimes connect before Postgres is fully up, see [1] for more details. [1] docker-library/postgres#146
To wait for a postgres container to be "ready", I've been using a script like this:
But it seems even this is too early. Is there any unequivocal way that another container can tell once the postgres container is ready to be provisioned, without resorting to more arbitrary wait timers?
The text was updated successfully, but these errors were encountered: