Closed adrian-tarau closed 4 years ago
You can include scripts to be executed after database initialization, for files that are .sh
, .sql
and .sql.gz
https://github.com/docker-library/docs/tree/master/mariadb#initializing-a-fresh-instance
Oh I see you mentioned that
We'd rather not add additional environment variables and instead expose areas (like /docker-entrypoint-initdb.d
) where users can add in their own (a custom shell script could even use new environment variables).
So something like this? It could even be built into a custom image.
#!/bin/bash
set -e
# as long as the file is not executable, it will be sourced by the entrypoint
# and have access to all the functions defined there (like docker_process_sql)
docker_process_sql <<-EOSQL
grant select on performance_schema.* to '$MY_CUSTOM_VARIABLE'@'%';
grant $SOME_PERMISSIONS on . to '$MY_OTHER_USER'@'%';
EOSQL
docker_process_sql <<<"$RAW_SQL_COMMAND;"
Well, I still think an env variable could be a useful feature...also easy to add. In the end, we made a custom image with custom SQL files to set up the database the way we needed for development.
Environment variable like MYSQL_DATABASE, MYSQL_USER, MYSQLPASSWORD allows one to create a user and a database when the container starts but if special permissions need to be given to that user the only way of doing that is to mount scripts under /docker-entrypoint-initdb.d_.
It would be much easier to set up complete test instances if an environment variable called MYSQL_INITDB_STATEMENTS (or something like that) would be supported to be able to inject alter statements like: