使用Oracle XE启动Docker容器后无法运行SQL脚本

时间:2018-10-08 13:35:44

标签: oracle docker

我想用Oracle XE启动一个Docker容器,然后运行一个SQL脚本(ddl.sql)在docker-compose中创建一些表。

如果我分别执行所有步骤,则一切正常:

$ 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-compose运行所有内容时(以下是YML的摘录)

version: "2"
services:
...
  db:
    image: wnameless/oracle-xe-11g
    container_name: vpk-db
    volumes:
      - ./ddl.sql:/home/vpk/ddl.sql
    command: sqlplus system/oracle@xe @/home/vpk/ddl.sql
    ports:
      - 49161:1521
    environment:
      - ORACLE_ALLOW_REMOTE=true
    networks:
      - default

我得到了错误:

ERROR: for 2237511031b6_vpk-db  Cannot start service db: b'OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \\"sqlplus\\": executable file not found in $PATH": unknown'

ERROR: for db  Cannot start service db: b'OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \\"sqlplus\\": executable file not found in $PATH": unknown'
Encountered errors while bringing up the project.

好的。我找到了sqlplus的完整路径

root@558a4c1f74b9:/# whereis sqlplus
sqlplus: /u01/app/oracle/product/11.2.0/xe/bin/sqlplus

并将其插入docker-compose

$ docker-compose.exe up
Removing vpk-db
Recreating 2237511031b6_vpk-db ... done
Attaching to vpk-db
vpk-db | Error 6 initializing SQL*Plus
vpk-db | SP2-0667: Message file sp1<lang>.msb not found
vpk-db | SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
vpk-db exited with code 1

这是怎么回事?我在运行docker-compose而不是docker run ... image时是否以其他用户身份登录?

1 个答案:

答案 0 :(得分:0)

尝试在docker-compose文件中使用下一个:

command: ["/bin/bash", "-c", "sqlplus system/oracle@xe @/home/vpk/ddl.sql"]

U没有没有外壳的环境,因此直接调用