Adding support for database startup scripts - #1142
Conversation
…mysql into database-startup-scripts
|
This ("
A full custom entrypoint implementing this for MySQL (the equivalent for PostgreSQL is worked out in docker-library/postgres#496, and the same #!/usr/bin/env bash
set -Eeuo pipefail
source /usr/local/bin/docker-entrypoint.sh
if [ "${1:0:1}" = '-' ]; then
set -- mysqld "$@"
fi
if [ "$1" = 'mysqld' ] && ! _mysql_want_help "$@"; then
mysql_check_config "$@"
docker_setup_env "$@"
docker_create_db_directories "$@"
if [ "$(id -u)" = '0' ]; then
exec gosu mysql "$BASH_SOURCE" "$@"
fi
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
ls /docker-entrypoint-initdb.d/ > /dev/null
docker_init_database_dir "$@"
docker_temp_server_start "$@"
mysql_socket_fix
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*
mysql_expire_root_user
docker_temp_server_stop
else
docker_temp_server_start "$@"
mysql_socket_fix
docker_process_init_files /always-initdb.d/*
docker_temp_server_stop
fi
fi
exec "$@"(See also: docker-library/postgres#267 (comment), docker-library/postgres#191 (comment), docker-library/postgres#821 (comment), docker-library/postgres#929, docker-library/postgres#955 (comment)) |
There are instances where you want to run scripts when the container starts, and not just when the database is first created. Here are some examples where this feature would be useful:
This merge request adds this capability by creating a new "/docker-entrypoint-startdb.d/" folder; files placed in this folder will be run on every container startup.
NOTE: The DockerHub image page description will need to be updated, with text that looks similar to this: