83 private links
Postgres docker containers have a problem of multiple restarts.
A simple way to check for them being 'up' up (i.e. initialized, reachable, and ready) is not through pg_isready
but instead by checking on the set database port (default 5432) if a connection can be established.
It will not send anything back really since it's not designed as an http server. So curl -sFfI db:5432
for example will get back 52 Empty Reply
with status code 52. If you want to check with that make sure to compare to error code 52!
The easiest option if another container has to wait for this one to start up (and especially in a docker stack environment where no wait_for option exists) is:
nc db 5432
which will only return true when the port is ready.
An example for the nextcloud fpm container waiting for database readiness:
entrypoint: sh -c "while !(nc -z db 5432); do sleep 1; done; /entrypoint.sh php-fpm"