Created
June 3, 2016 08:15
-
-
Save revington/e97df11396f983906e0b8432f30e21bc to your computer and use it in GitHub Desktop.
mysql docker container start and wait until ready
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MYSQL_ROOT_PASSWORD=root | |
function docker_container_ip { | |
docker inspect "$1" | jq -r '.[0] | .NetworkSettings | .IPAddress' | |
} | |
echo "Run mysql container" | |
mysql_id=$(docker run -d -e MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD mysql) | |
mysql_host=`docker_container_ip "$mysql_id"` | |
function wait_until_mysql_ready { | |
printf 'Waiting for mysql' | |
while [ 1 ] | |
do | |
printf '.' | |
local response=`mysql -h "$mysql_host" -u root -p"$MYSQL_ROOT_PASSWORD" -e "SHOW DATABASES" 2> /dev/null` | |
if [ $(grep 'information_schema'<<< "$response" -c) -ne 0 ] | |
then | |
printf '\n' | |
break | |
fi | |
sleep 1 | |
done | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment