Tech Noob
Tech Noob

Reputation: 550

Sqlplus not found in oracle docker mage

I have a working oracle image, which I can use run then use docker exec to get into the running container and execute sqlplus command with no issue.

Now I am trying to create a new image with some initial data using this image. Here is my docker file.

FROM oracle:12.2

USER root

COPY /testingData /testingData

RUN chown -R oracle:oinstall /testingData
RUN chmod -R 755 /testingData

USER oracle
RUN /testingData/runInitSQLScript.sh

And here is my sh file

#!/bin/bash

sqlplus -s /nolog << EOF
CONNECT sys as SYSDBA/testpass;

whenever sqlerror exit sql.sqlcode;
set echo off
set heading off

@/sql/mytestingData.sql

exit;
EOF

It kept telling me sqlplus command not found

When I try to use the full path of the sqlplus like this @ORACLE_HOME/bin/sqlplus, it still says the same. Then I tried to check on the path, I realize I can only get into one layer under the root directory, for example, if my ORACLE_HOME is /u01/app/oracle/product/12.2.0/dbhome_1/, I can only cd into /u01, when I do cd /u01/app, it start to say that directory not found. Please help. Thanks.

Upvotes: 1

Views: 2290

Answers (2)

Adiii
Adiii

Reputation: 60094

update: As per @Sayan comment the sqlplus exist on $ORACLE_HOME/bin/sqlplus path. OR

the other option is to use below docker image to connect with Oracle database container

docker run --interactive guywithnose/sqlplus sqlplus {CONNECTION_STRING}

or use legacy linking to better to use docker network

docker run --it --link db guywithnose/sqlplus sqlplus {CONNECTION_STRING}

Now you can use db as host name for db connection.

https://github.com/sflyr/docker-sqlplus

Upvotes: 1

Sayan Malakshinov
Sayan Malakshinov

Reputation: 8665

If you image is similar to official images, it installs Oracle software and creates database only after the start of container. So at the moment when you create image, ORACLE_HOME directory doesn't exist yet. In case of official images, I'd suggest you to put your scripts into one of these 2 special folders:

   -v /opt/oracle/scripts/startup | /docker-entrypoint-initdb.d/startup
                  Optional: A volume with custom scripts to be run after database startup.
                  For further details see the "Running scripts after setup and on startup" section below.
   -v /opt/oracle/scripts/setup | /docker-entrypoint-initdb.d/setup
                  Optional: A volume with custom scripts to be run after database setup.
                  For further details see the "Running scripts after setup and on startup" section below.

More about this: https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance

Upvotes: 2

Related Questions