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

Postgres: Add healthcheck examples #2393

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions postgres/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ postgres=# SELECT 1;

Run `docker stack deploy -c stack.yml %%REPO%%` (or `docker-compose -f stack.yml up`), wait for it to initialize completely, and visit `http://swarm-ip:8080`, `http://localhost:8080`, or `http://host-ip:8080` (as appropriate).

## Healtcheck
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Healt/Health/


To add a health check to the image use the following command:

```console
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword \
LaurentGoderre marked this conversation as resolved.
Show resolved Hide resolved
--health-cmd='pg_isready' --health-interval=5s -d %%IMAGE%%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't just a raw pg_isready like this happily connect to the temporary unix-socket-only instance of the server that's used for initdb, and thus prematurely report that the database is up and healthy?

(see also https://github.com/docker-library/faq#healthcheck, many of which applies to trying to make "generic" documentation for health checks too, and https://github.com/docker-library/healthcheck/blob/40afbf64d69cf933af0da4df6383958a29113601/postgres/docker-healthcheck which is likely more than we'd want in the documentation but the main point there being explicitly using TCP to ensure we don't connect to the temporary server)

```

or using docker-compose

```yaml
services:
postgres:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
healthcheck:
test: pg_isready
interval: 5s
```

# How to extend this image

There are many ways to extend the `%%REPO%%` image. Without trying to support every possible use case, here are just a few that we have found useful.
Expand Down