Skip to content

Instantly share code, notes, and snippets.

@krukru
Created July 23, 2018 16:32
Show Gist options
  • Save krukru/8c6003c43fe5b58175bee0431c3ebfdd to your computer and use it in GitHub Desktop.
Save krukru/8c6003c43fe5b58175bee0431c3ebfdd to your computer and use it in GitHub Desktop.
Wait until docker container is healthy
#!/usr/bin/env bash
CONTAINER_HEALTH=$(docker inspect --format='{{json .State.Health.Status}}' $1)
if [ -z $CONTAINER_HEALTH ]; then
echo "Container not found"
exit 1
fi;
until test $CONTAINER_HEALTH = "\"healthy\""; do
echo "Waiting..."
sleep 1
CONTAINER_HEALTH=$(docker inspect --format='{{json .State.Health.Status}}' $1)
if [ -z $CONTAINER_HEALTH ]; then
echo "Container crashed"
exit 1
fi;
done
echo "Ready!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment