On an docker image's entrypoint shell script I want to determine if a postgresql container can listen to connections. For mysql I used the following snippet:
while ! mysqladmin ping -h"$MOODLE_DB_HOST" -P $MOODLE_DB_PORT --silent; do
echo "Connecting to ${MOODLE_DB_HOST} Failed"
sleep 1
done
How can I achieve a similar using postgresql?
Best Answer
On the dockerfile add:
Then on the entrypoint script use:
Another approach
An another approach is by using netcat:
Where variable
${DB_HOST}
contains the database host whilst${DB_PORT}
contains the database port. Thas works on most databases (except if you want to detect its type as well where a custom script is needed).