Public | Automated Build

Last pushed: 3 years ago
Short Description
Short description is empty for this repo.
Full Description


This image is based on mariadb:latest and produces a container that basically wakes up mariadb as expected
and then executes sql statements from /root.sql file if exists and then from /${MYSQL_DATABASE}.sql if found.
(but only if a user, password and database were specified).

It waits 15s by default before executing the sql statements to let mariadb process to wake up properly.

The /root.sql statements are executed EACH TIME the container is started, but /${MYSQL_DATABASE}.sql is
only executed once per container (container volume) for the same database. Even if the content of the file
is changed, the database name is the same, so the file is not executed.

Usage Examples

Execute statements in host files named root-statements.sql after 15s of starting the container:

    docker run -e MYSQL_ROOT_PASSWORD=secretpass \
               -v $(pwd)/root-statements.sql:/root.sql \

Execute statements in both /root-statements.sql and inserts.sql after 30s of starting the container:

    docker run -e MYSQL_ROOT_PASSWORD=secretpass \
       -e MYSQL_DATABASE=exampledb \
       -e MYSQL_USER=auser \
       -e MYSQL_PASSWORD=apass \
       -e SQL_EXEC_DELAY=30 \
               -v $(pwd)/root-statements.sql:/root.sql \
               -v $(pwd)/inserts.sql:/exampledb.sql \

Notice that the -v flag is used for mounting the files located in the host to the expected file names
used from inside the container: /root.sql and ${MYSQL_DATABASE}.sql

  • Allow specifying a URL as the source for the sql statements file (maybe to allow fetching from github/bitbucket)
  • Wait for the mysqld process to start listening instead of optimistically waiting some time before sql file execution
Docker Pull Command
Source Repository