docker-library / postgres

Docker Official Image packaging for Postgres

Home Page:http://www.postgresql.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a HEALTHCHECK to the images

kodedylf opened this issue · comments

When helping people on StackOverflow, I often see people having problems with Docker Compose and applications that try to connect to the database immediately on startup. When using a simple docker compose 'depends_on' directive, compose only waits for the database to be started before starting the application. The application then fails because the database isn't ready to accept connections yet.

The solution is to add a healthcheck to the database container in docker compose and have the application wait for the database to enter a healthy state.

It would be nice if the healthcheck was included in the Postgres image by default. A simple HEALTHCHECK ["pg_isready"] should be enough.

Some of this is discussed in #920

Why not include healthcheck script but not enable it by default to make things a bit easier?

IMHO included healthcheck should have these features:

  • ensures all init scripts are done
  • ensures db can be queried (SELECT 1)
  • allows user to provide custom query via env variable