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"
FoldFold allExpandExpand allAre you sure you want to delete this link?Are you sure you want to delete this tag?
The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community