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

Detect when container is ready #316

Open
latot opened this issue Oct 14, 2022 · 6 comments
Open

Detect when container is ready #316

latot opened this issue Oct 14, 2022 · 6 comments

Comments

@latot
Copy link

latot commented Oct 14, 2022

Hi all, I'm trying to use postgis for apps, but is hard because I can't found a way to know when a contianer is ready (I can need mount several of them).

Is not like there is no way to check the logs with regex, but I think would be great have a way to can now when the container is ready.

There is a important thing about this type of container, I checked docker-library/postgres#146, sadly does not has a cross-platform solution, pg_isready helps in the postgres case, but in case of postgis not, because after postgres is mounted, then the extensions must be installed and then the server restarts, due to this pg_ready ends in the installation of the extension because is a moment where postgres is working.

There can be different solutions, maybe a cross-platform way, is to have a file in the root of the container with the a general status of the container, where checking it we can now when the container is ready, maybe someone else have a robust solution to that.

Thx!

@ImreSamu
Copy link
Member

Hi latot,

... and then the server restarts,

As I understand, the ~"temporary daemon" is running only on the Unix socket.

And there is ~ good documentation about the initialization steps used by this project.

pg_isready

so if you don't want to connect to the ~"temporary daemon" ( via Unix socket. )
try the opposite and ADD the hostname!

until pg_isready -h $(hostname -i); do
  sleep 0.1
done

( as suggested in docker-library/postgres#146 (comment) )

@latot
Copy link
Author

latot commented Oct 14, 2022

Hi!, pg_isready does not works very well in postgis (in postgres works), because when postgis is installing the extesion, pg_isready tells the server is ready. After the installation the server is restarted, so wait pg_isready is not very good here D:

@ImreSamu
Copy link
Member

Hi!, pg_isready does not works very well in postgis

If I understand you correctly, you re-tested pg_isready with the --host parameter and it did not solve your problem.
ouch ...
In that case, please provide a minimal working example that I can check.

@ImreSamu
Copy link
Member

my suggestion is the same as the upstream suggestion

  • "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)."

via docker-library/postgres#146 (comment)

@latot
Copy link
Author

latot commented Oct 14, 2022

Hi, I think I don't understand you exaplain in your first comment, now I get it, I'll test probable monday, thx for your help :)

@latot
Copy link
Author

latot commented Oct 17, 2022

Hi!, well, first sorry, my redaction was very ugly in the last comment.

And yes, the method works!, I think can be easy have it in the docs more than in the comments, in order to do this works in cross platform, I'm doing the next thing, first instead run the complete sh script, only run pg_isready and get the timer over the language we are using, for now I'm using R, but this is applicable to any language:

while (TRUE){
    Sys.sleep(5)
    if (
        processx::run(
            "docker",
            c(
                "exec",
                postgres_docker_id,
                "pg_isready",
                "-h", "localhost"
            ),
            error_on_status = FALSE
        )$status == 0
    ) break
}

I think the last thing, is ideally update the docs and specify how to use pg_isready.

Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants