Skip to content

Instantly share code, notes, and snippets.

@revington
Created June 3, 2016 08:15
Show Gist options
  • Save revington/e97df11396f983906e0b8432f30e21bc to your computer and use it in GitHub Desktop.
Save revington/e97df11396f983906e0b8432f30e21bc to your computer and use it in GitHub Desktop.
mysql docker container start and wait until ready
#!/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