guneysus
4/4/2016 - 10:25 AM

Wait application to run completely in a docker container from https://docs.docker.com/compose/startup-order/

Wait application to run completely in a docker container from https://docs.docker.com/compose/startup-order/

#!/bin/bash

# Usage:
# You can use this as a wrapper script as in the previous example, 
# by setting entrypoint: ./waitfor.sh db
set -e

host="$1"
shift
cmd="$@"

until psql -h "$host" -U "postgres" -c '\l'; do
  >&2 echo "Postgres is unavailable - sleeping"
  sleep 1
done

>&2 echo "Postgres is up - executing command"
exec $cmd