5

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.

4
  • 1
    have you checked the user permission on this file ? or checked the container logs ? Note that you need to create a new container during the test i think this will be executed one time only Commented Feb 25, 2019 at 11:32
  • The permissions are fine. The container logs report nothing regarding the sql queries that should be executed, it seems like they are not being executed at all. Commented Feb 25, 2019 at 12:04
  • What about the entrypoint itself, can you check it to confirm ? Does it support this feature in specific ? I mean might be a new version of the container is needed which provides a support for it but worth checking anyway Commented Feb 25, 2019 at 12:09
  • The command "ADD dbModelAndInit.sql /docker-entrypoint-initdb.d/" simply add a file to an image. Who execute it? Commented Feb 25, 2019 at 12:12

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This was it, I changed the image used and it started working normally. Thanks.
@Dragan which image did you use then?
0

In my case, I've had to tell the DB configuration script directly to run my .sql scripts.

  1. Run the container.

  2. Copy the configuration script from home/oracle/setup/configDBora.sh.

  3. 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
    
  4. Rebuild the image replacing the configuration file.

  5. Any all the .sql scripts that you put in that folder will run now when creating the container.


Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.