You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I need to execute my script during the first database initialization, for example, I want to create additional users and give them rights. I faced the difficulty of customizing my script.
A. use /docker-entrypoint-initdb.d/*
I looked at run.sh and it became clear that I can only place .sql and .sql.gz files in this directory. But I need to pass environment variables to this file. Is there any way I can do this? Not resorting to parsing via build, but only mounting the directory using volumes in my docker-compose.yml? Also, I can't run sh scripts in this directory.
B. use /scripts/pre-exec.d/*sh
Here I can already place my script through volumes, in which environment variables are available, but the problem is that this script is called every time, but need to do it on first start. In run.sh uses the condition if [ -d /var/lib/mysql/mysql ] which is no longer relevant at the time of script execution.
At the moment, I found the following solutions to my problem:
Enable execution of .sh scripts in the /docker-entrypoint-initdb.d directory
Add parsing .sql files to replace ${VAR} to environment variables
Add to my sh script the creation of a directory/file (flag) to check if the container is running for the first time.
The third option suits me best, but looks like a crutch (it is necessary to ensure that in each script there is such a check).
Use the first two options, I can only if I completely replace the run.sh script when building the image, which is a problem, since this script can be updated.
I can do a PR and modify run.sh, but first I want to hear your opinion. The first option seems to me more suitable (and is easier to implement), since plain sql is not enough.
The text was updated successfully, but these errors were encountered:
Hi! I need to execute my script during the first database initialization, for example, I want to create additional users and give them rights. I faced the difficulty of customizing my script.
A. use /docker-entrypoint-initdb.d/*
I looked at run.sh and it became clear that I can only place .sql and .sql.gz files in this directory. But I need to pass environment variables to this file. Is there any way I can do this? Not resorting to parsing via build, but only mounting the directory using volumes in my docker-compose.yml? Also, I can't run sh scripts in this directory.
B. use /scripts/pre-exec.d/*sh
Here I can already place my script through volumes, in which environment variables are available, but the problem is that this script is called every time, but need to do it on first start. In run.sh uses the condition
if [ -d /var/lib/mysql/mysql ]
which is no longer relevant at the time of script execution.At the moment, I found the following solutions to my problem:
The third option suits me best, but looks like a crutch (it is necessary to ensure that in each script there is such a check).
Use the first two options, I can only if I completely replace the run.sh script when building the image, which is a problem, since this script can be updated.
I can do a PR and modify run.sh, but first I want to hear your opinion. The first option seems to me more suitable (and is easier to implement), since plain sql is not enough.
The text was updated successfully, but these errors were encountered: