Reputation: 229
Somewhat surprisingly, I have been unable to find an answer to this, which I feel is a common situation.
So, I am trying to write a docker file in which I would initialize an oracle database and then run a script with SQL queries.
In my folder, I have the following files: dockerfile, dbInit.sql
My dockerfile looks like this:
FROM store/oracle/database-enterprise:12.2.0.1-slim
ADD dbModelAndInit.sql /docker-entrypoint-initdb.d/
EXPOSE 1521
After building and running the image, a database is running, but the file is not executed.
Any help would be greatly appreciated.
Upvotes: 5
Views: 4124
Reputation: 1
In my case, I've had to tell the DB configuration script directly to run my .sql
scripts.
Run the container.
Copy the configuration script from home/oracle/setup/configDBora.sh
.
Modify the script by adding the following snippet just before the ## db network set # sqlnet.ora block
:
# Custom scripts on start up
echo "====> Checking for custom scripts on startup..."
if [ ! "$(ls -A /home/oracle/setup/your_scripts/*.sql)" ]; then
echo "/home/oracle/setup/your_scripts is empty!"
else
echo "/home/oracle/setup/your_scripts is not empty"
for filename in /home/oracle/setup/your_scripts/*.sql; do
echo "Executing file $filename..."
sqlplus / as sysdba 2>&1 <<EOF
@$filename;
exit;
EOF
done
fi
Rebuild the image replacing the configuration file.
Any all the .sql scripts that you put in that folder will run now when creating the container.
Upvotes: 0
Reputation: 113
I have the same problem and as far as I know, files in "docker-entrypoint-initdb.d" are executed automatically, is that right? But I'm not sure that is this particular image "store/oracle/database-enterprise:12.2.0.1-slim" the scripts placed in this path are executed automatically.
Upvotes: 1