Run the container with links to mysql and the database file available through volumes or volumes_from.
-
-
Save cstpraveen/dd58c69f37b333440ec2e09a2f4f4eea to your computer and use it in GitHub Desktop.
Docker wait for mysql to be ready and then load sql
This file contains hidden or 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 hidden or 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