Run the container with links
to mysql
and the database file available through volumes
or volumes_from
.
Created
November 8, 2016 15:54
-
-
Save ricog/9e745cd79824bc360df14bdf95bb1f27 to your computer and use it in GitHub Desktop.
Docker wait for mysql to be ready and then load sql
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
FROM mysql:5.6 | |
MAINTAINER Your Name <[email protected]> | |
COPY wait-for-mysql.sh / | |
CMD /wait-for-mysql.sh |
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
HOST="$MYSQL_PORT_3306_TCP_ADDR" | |
PORT="$MYSQL_PORT_3306_TCP_PORT" | |
USER="root" | |
PASSWORD="$MYSQL_ENV_MYSQL_ROOT_PASSWORD" | |
DATABASE="$MYSQL_ENV_MYSQL_DATABASE" | |
SQL_PATH="${SQL_PATH:-/var/www/Config/sql}" | |
echo $SQL_FILE; | |
SQL_FILE="${SQL_FILE:-database.sql}" | |
echo $SQL_FILE; | |
until echo '\q' | mysql -h"$HOST" -P"$PORT" -u"$USER" -p"$PASSWORD" $DATABASE; do | |
>&2 echo "MySQL is unavailable - sleeping" | |
sleep 1 | |
done | |
while [ ! -d $SQL_PATH ]; do | |
>&2 echo "Data is unavailable - sleeping" | |
sleep 1; | |
done; | |
>&2 echo "MySQL and Data are up - executing command" | |
cat $SQL_PATH/$SQL_FILE | mysql -h"$HOST" -P"$PORT" -u"$USER" -p"$PASSWORD" $DATABASE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
QUIT from MySQL CLI