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
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With