我想启动一个带有Oracle XE的Docker容器,然后运行一个SQL脚本(ddl.sql)来创建一些表。
如果我分开执行所有步骤,一切都正常:
$ 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
在容器中运行终端:
$ docker exec -it db bash
执行脚本:
root@f3ae34d554af:/# echo exit | sqlplus system/oracle@xe @/home/vpk/ddl.sql
然而,当我尝试将最后两个步骤合并为一个时:
$ 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
即使使用完整路径调用sqlplus也没有帮助:
$ 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
错误的原因是什么?
在@maxm的帮助下,我成功地运行了:
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"
然而,我希望在sqlplus提示符退出后自动退出。但是当我尝试添加
echo exit
并运行它时: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"
我遇到了错误:
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