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
SP2-0750indicates that theoraenvscript 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.