3

I want to start a Docker-container with Oracle XE and then run an SQL script (ddl.sql) to create some tables.

If I execute all the steps separately, everything works:

$ docker run -d --name db --rm -p 49161:1521 -v "C:/data/workspace/vpk/":/home/vpk -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g

Run a terminal in container:

$ docker exec -it db bash

Execute the script:

root@f3ae34d554af:/# echo exit | sqlplus system/oracle@xe @/home/vpk/ddl.sql

However when I tried to combine the last two steps into one:

$ docker exec db sqlplus system/oracle@xe @/home/vpk/ddl.sql

I got the error:

OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"sqlplus\": executable file not found in $PATH": unknown

Using the full path of sqlplus didn't help either:

$ docker exec db bash -c "/u01/app/oracle/product/11.2.0/xe/bin/sqlplus system/oracle@xe /home/vpk/ddl.sql"
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

What is the reason of the error?

With the help of @maxm I was able to successfully run:

docker exec -it db /bin/bash -c "ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe /u01/app/oracle/product/11.2.0/xe/bin/sqlplus system/oracle@xe @/home/vpk/ddl.sql"

However I would like to exit the sqlplus prompt afterwards. But when I tried to add echo exit to it and run:

docker exec -it db /bin/bash -c "ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe; echo exit | /u01/app/oracle/product/11.2.0/xe/bin/sqlplus system/oracle@xe @/home/vpk/ddl.sql"

I got the error:

Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
4
  • download the Oracle instant client(which includes sqlplus ) in your local and access the database in the container. Commented Oct 8, 2018 at 14:50
  • @KaushikNayak I want to do everything in a shell script without any installations. As the first 3 commands shown the db can be created. So no additional tools are required. Commented Oct 8, 2018 at 14:55
  • Did your container installed sql plus? And the path included sql plus. You can try echo $PATH or which sqlplus to confirm it is exist in container. Commented Oct 8, 2018 at 15:15
  • SP2-0750 indicates that the oraenv script was not "sourced" -- it is usually done in a .profile/.bash_profile; it sets ORACLE_HOME, ORACLE_SID, PATH, and others based on certain environment variables. Commented Oct 8, 2018 at 15:44

2 Answers 2

4

The sqlplus bin location is added to your PATH in the .bashrc, see this line in the setup:

echo 'export PATH=$ORACLE_HOME/bin:$PATH' >> /etc/bash.bashrc

When you run exec directly without calling bash it's going to try and run the command with sh -c and the .bashrc won't be loaded. Try running this to run the file directly:

docker exec db /u01/app/oracle/product/11.2.0/xe/bin/sqlplus system/oracle@xe @/home/vpk/ddl.sql

I also though running with bash -c "command" might load .bashrc, but it doesn't seem to, might want to read up on how bash loads the .bashrc file.

Edit:

As referenced in the comment below ORACLE_HOME isn't set. This command should work:

docker exec -it db /bin/bash -c "ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe /u01/app/oracle/product/11.2.0/xe/bin/sqlplus system/oracle@xe /home/vpk/ddl.sql"
Sign up to request clarification or add additional context in comments.

6 Comments

Please, see edited question. I've just put the execution result. There must be some root problem. Maybe wrong user... that's why "sqlplus" and other files aren't "seen".
Hmm, this is quite verbose, but this works: docker exec -it db /bin/bash -c "ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe /u01/app/oracle/product/11.2.0/xe/bin/sqlplus system/oracle@xe /home/vpk/ddl.sql"
source /etc/bash.bashrc should also work, but I can't seem to get it to set the correct env vars during the session
maxm Your command works. But I would like to exit the sqplus prompt afterwards. I've edited my question. Please, see the last commands there.
Hmm, I think if you just remove the -it from the command SQL won't spawn a shell and the command will exit.
|
0

I know it may seem a little "silly" on my part, but remember to allow time for the instance to finish being instantiated. The 12c Enterprise Edition, p. eg, takes around 10min to be instantiated completely and the database created for use

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.