Skip to content

Instantly share code, notes, and snippets.

@pitervergara
Created September 14, 2016 04:14
Show Gist options
  • Select an option

  • Save pitervergara/0e5dc66890e6a7e5b96c8ead6d91fc37 to your computer and use it in GitHub Desktop.

Select an option

Save pitervergara/0e5dc66890e6a7e5b96c8ead6d91fc37 to your computer and use it in GitHub Desktop.
Docker entrypoint to test and wait for service dependencies
```bash
#!/bin/bash
# List all deps using this format: ("host port", "host port"). Remember to link the container using the 'host' name.
requirements=("postgis 5432" "redis 6379" "elasticsearch 9200")
cmd="$@"
missing_requirement=true
while [ "${missing_requirement}" == "true" ]
do
missing_requirement=false
sleep 1
for req in "${requirements[@]}"
do
if ! nc -z $req
then
echo "Waiting for ${req} to be up"
missing_requirement=true
else
echo "${req} is up!"
fi
done
done
>&2 echo "All required services are up. Let's move on..!"
exec $cmd
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment