Skip to content

add Healthcheck #1146

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
wants to merge 1 commit into from
Closed

Conversation

ygerlach
Copy link

This allows to check for the health of the postgres container. This is usefull for docker-compose.
Services might use:

depends_on:
  mypostgres-container:
    condition: service_healthy

to check for a up and running postgres instance

normaly i would check for the open tcp port, but postgres starts the temporary server to setup the db. Those might cause a simple port check (like grep -q ":1538" /proc/net/tcp ) to report a false positive.
This might also not be a guarante, that the server is available. Maybe it would be a good idea to check for the shm and the port like this:

HEALTHCHECK --interval=1s --timeout=1s --retries=60 \
	CMD-SHELL test -f /dev/shm/ready && grep -q :1538 /proc/net/tcp

Let me know what you think.
Just a simple "process is running" check, or an advanced "process is running and post is open" check or an even more advanced "process is running and a SELECT 1; query works"

I just implemented it for one Dockerfile now. If you are fine with this, i would add this to every Dockerfile.

@LaurentGoderre
Copy link
Member

We have a PR open for healthcheck with postgres. I am wondering if it would solve your issue: https://github.com/docker-library/docs/pull/2393/files

@ygerlach
Copy link
Author

ygerlach commented Nov 24, 2023

That looks promising, i havent tried it yet, but it looks, like that could (like a simple port check) also trigger during the startup phase of the container, when the server is started temporary for db setup. That could cause problems with depending services. Maybe a combination of the shm file to mark, that the server is started for real and pg_isready to make sure the server accepts connections would work. I am going to try that.

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

Successfully merging this pull request may close these issues.

3 participants