Skip to content

Confirm a container is ready to run after init #326

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

Closed
bizmate opened this issue Aug 15, 2017 · 5 comments
Closed

Confirm a container is ready to run after init #326

bizmate opened this issue Aug 15, 2017 · 5 comments

Comments

@bizmate
Copy link

bizmate commented Aug 15, 2017

Hi folks,
the innit process is great to just do exactly what it promises and it runs only the first time the data created as the rule is to check if a file was already created before running init to make sure it is ok

ie

echo 'PostgreSQL init process complete; ready for start up.'

In my local processes for development I tend to use docker compose and unless i want a custom check to verify that a container is running i then listed to logs for a specific sentence. For instace for an apache container i check that this has run
[Tue Aug 15 12:57:35.380606 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

If the init is running in the postgres container i can wait for
PostgreSQL init process complete; ready for start up.

Any objection to run an else condition to echo
PostgreSQL init process skipped; ready for start up.

I can create a PR but wanted to check with you before.

@yosifkit
Copy link
Member

I'd instead recommend checking for connectivity, rather than a log message. That is what we do in the Wordpress image. The log message will stick around in the logs on a container restart and will then appear again for each restart.

@bizmate
Copy link
Author

bizmate commented Aug 17, 2017

Connectivity does not tell if the init has finished and I would rather not rely on a custom query to verify the dataset/config is ready when i can lazily and cheaply check a log. This is also because my init might do nothing or a lot depending on what scripts i mount in the init folder.
A simple echo (as there is one already when the process runs) that the init was skipped would at least confirm that there is nothing else spinning in the container and you can assume the your container is ready as you expect it because the init was run in a previous spin (for instance if like me you also use volumes).

@yosifkit
Copy link
Member

Actually remote connectivity does tell if the init has finished (i.e. any connection from another container or the host). For the init process, the postgres server is started in localhost only mode, so once it is available remotely, it has already finished any init scripts and been restarted to listen publicly.

@tianon tianon closed this as completed Sep 15, 2017
@Simran-B
Copy link

FYI When using Docker Compose healthcheck to determine readiness, it is crucial to use the hostname (defined by the services key), like pg_isready --host=THE_HOSTNAME, to not incorrectly return successfully because Postgres accepts local connections during initialization.

@tianon
Copy link
Member

tianon commented Apr 15, 2024

See https://github.com/docker-library/healthcheck/blob/40afbf64d69cf933af0da4df6383958a29113601/postgres/docker-healthcheck for an example implementation that does effectively that, but in a generalized way (using the external IP via forced TCP connection) 👍

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

4 participants