This Dockerfile is a wrapper over the MySQL Command-Line Tool.
This Dockerfile is similar to senzing/mysql, but differs in the following ways:
- The command is only run once.
A "Sentinel File" is created on the first run.
It prevents future runs.
The file should be located on an external volume.
Default location:
/opt/senzing/mysql-init.sentinel
. - On the first run, the command loops until it succeeds.
This is useful in docker-compose formations where the
mysql
command needs to wait for mysql server to come up. An example is at senzing/docker-compose-mysql-demo.
docker build --tag senzing/mysql-init https://github.com/senzing/docker-mysql-init.git
-
Identify the file of SQL to be run. Example: If the actual file pathname is
/path/to/mysqlfile.sql
export MYSQL_DIR=/path/to export MYSQL_FILE=mysqlfile.sql
-
Identify the database username and password. Example:
export MYSQL_USERNAME=root export MYSQL_PASSWORD=root
-
Identify the database that is the target of the SQL statements. Example:
export MYSQL_DATABASE=mydatabase
-
Identify the host running mySQL servers. Example:
docker ps # Choose value from NAMES column of docker ps export MYSQL_HOST=docker-container-name
-
Identify the Docker network of the mySQL database. Example:
docker network ls # Choose value from NAME column of docker network ls export MYSQL_NETWORK=nameofthe_network
-
Identify where the "sentinel file" should be located. The file should be on an external volume. Example:
export SENZING_SENTINEL_FILE="${MYSQL_DIR}/mysql-init.sentinel"
-
Create the docker container. Note: parameters after senzing/mysql-init are mysql CLI options.
docker run -it \ --volume ${MYSQL_DIR}:/sql \ --net ${MYSQL_NETWORK} \ --env SENZING_SENTINEL_FILE=${SENZING_SENTINEL_FILE} \ senzing/mysql-init \ --user=${MYSQL_USERNAME} \ --password=${MYSQL_PASSWORD} \ --host=${MYSQL_HOST} \ --database=${MYSQL_DATABASE} \ --execute="source /sql/${MYSQL_FILE}"