Skip to content

Instantly share code, notes, and snippets.

@sankar4n
Forked from zhashkevych/Dockerfile
Last active July 24, 2022 08:09
Show Gist options
  • Save sankar4n/132c4ccc9a1b266c093d7ddb374f14af to your computer and use it in GitHub Desktop.
Save sankar4n/132c4ccc9a1b266c093d7ddb374f14af to your computer and use it in GitHub Desktop.
Wait for Postgres initialization in Docker-Compose
#!/bin/sh
set -e
until psql -d "postgres" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Ensuring database..."
psql -d postgres -c "CREATE DATABASE \"$PGDATABASE\";" || true
>&2 echo "Postgres is up!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment