-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Request: adding Docker health check to postgres/README.md
#2391
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
The following works for me:
|
@LaurentGoderre can you tell me what this outputs for you? docker compose run postgres pg_isready
# or
docker compose run postgres pg_isready --username user --dbname db And also thanks for sharing your config, appreciate your help! |
Running that command doesn't give you real result because you are overwriting the command so the postgres doesn't start. A better way would be
|
Ah I see, thank you!! One follow up question, is the ---
version: "3.8"
services:
postgres:
image: postgres:16.1-bookworm
ports:
- "5432:5432"
healthcheck:
test: pg_isready
start_period: 0s
environment:
POSTGRES_HOST_AUTH_METHOD: trust > time docker compose up --detach --wait postgres
...
docker compose up --detach --wait postgres 0.20s user 0.16s system 1% cpu 31.287 total We see it takes about 31 seconds. Now removing the
We see it worked within about 1 second. Why is the |
Update, I have realized from https://docs.docker.com/engine/reference/builder/#healthcheck the default So moving to: healthcheck:
test: pg_isready
interval: 1s This solved the issue: > time docker compose up --detach --wait postgres
...
docker compose up --detach --wait postgres 0.10s user 0.06s system 7% cpu 2.053 total |
|
It would be good to add a
healthcheck
to thepostgres/README.md
.There are some possible starting points posed here: https://stackoverflow.com/questions/65115627/safe-ways-to-specify-postgres-parameters-for-healthchecks-in-docker-compose
Aside: running the below:
I can never get
pg_isready
to output something besides/var/run/postgresql:5432 - no response
The text was updated successfully, but these errors were encountered: