15

I installed oracle db version 12c in my docker environment. I used the following command:

docker run -d --name oracle -p 8080:8080 -p 1521:1521 quay.io/maksymbilenko/oracle-12c

I connected to the DB and everything went well but I wanted to enable unified audit. In order to do that, at first you must shutdown the Database and in all the instructions that I found it says to use sqlplus as following:

sqlplus / as sysoper
SQL> shutdown immediate
SQL> exit

I connected successfully to the DB using the next command:

docker exec -it oracle "bash"

and then I ran the sqlplus command and I received "command not found"

[root@f30cc670f85f /]#   sqlplus / as sysoper
bash: sqlplus: command not found

Am I doing it wrong? What should I do in order to have sqlplus on my oracle DB? I looked for it and didn't find anything that helped me.

I have mac if its relevant

Tal Levi
  • 363
  • 1
  • 6
  • 22

7 Answers7

5

I think that Docker image is just the database and enough of the OS to run the database. I don't think it includes client software such as SQL*Plus.

You need to have SQL*Plus installed on your Mac. If you haven't already, download the Oracle Instant Client for MacOS including the SQL*Plus extension. Or why not treat yourself and install the new-fangled sqlCL tool? It is easier to install and has all the SQL*Plus capabilities and a whole bunch more features. Find it here.

Whatever client you choose, once it's installed on your Mac you run it like any other app: when prompted for connection you give the string Maksym provides:

sqlplus user/password@ip:port/service-name
sqlplus system/oracle@//localhost:1521/xe 

If you need to connect as sys that would look like this:

sqlplus sys/oracle@//localhost:1521/xe as sysdba
jumping_monkey
  • 5,941
  • 2
  • 43
  • 58
APC
  • 144,005
  • 19
  • 170
  • 281
  • ok, so I download sqlplus to my mac and I ran your command and it worked! I received the "SQL>" as I wanted. by any chance do you know how to continue from here and enable unified audit on my oracle db? – Tal Levi Nov 14 '19 at 14:20
  • 3
    As mentioned on the answers below. The docker images does contain the SQL plus. Just run `source /home/oracle/.bashrc;` and then you can run sql plus – orellabac Apr 24 '21 at 14:41
5

with this, you enter the image:

docker exec -it oracle /bin/bash

after that, you can use:

sqlplus sys as sysdba
3

Sourcing the .bashrc should work to connect to sqlplus as sysdba. docker-compose exec db bash -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1@ORCLCDB as sysdba;"

JayDP123
  • 71
  • 7
2

For Windows OS:

Type docker ps in command line to show running containers and check container id.

Type docker exec -it container_id //bin/bash

Login via sqlplus command

Or the simplest way

docker exec -it container_id bash -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1@ORCLCDB as sysdba;"

More info is here: https://docs.oracle.com/en/database/oracle/oracle-database/21/deeck/index.html#DEEDK-GUID-EDA557B2-B0D6-45E1-8FBD-C1D756803982

szachMati
  • 196
  • 2
  • 12
  • This link is no longer valid, possibly due to the Docker Hub corporatization. Is there a current version of this guidance? – David Cobb Mar 24 '23 at 15:59
  • 1
    @DavidCobb I think you can find some info in official Oracle page https://docs.oracle.com/en/database/oracle/oracle-database/21/deeck/index.html#DEEDK-GUID-EDA557B2-B0D6-45E1-8FBD-C1D756803982 – szachMati Mar 26 '23 at 14:42
1

When using the docker image store/oracle/database-enterprise:12.2.0.1-slim sqlplus and sqlldr tools are only available after the container has started. You can't do the following in a Dockerfile:

RUN sqlplus sys/password AS SYSDBA @create_database.sql

The container images can be configured to run scripts after setup and on startup. Currently sh and sql extensions are supported.

In your Dockerfile, copy the SQL script into the startup directory:

COPY create_database.sql  /opt/oracle/scripts/setup/01_create_database.sql

The database will be created on first startup of the container.

0

I don't have any experience with docker, but it looks for all the world like you are getting to a bash environment, so there we are on solid ground. The returned error ("bash: sqlplus: command not found") simply means that the executable (sqlplus) was not found in any directory listed in your PATH environment variable, as it exists within your shell environment. You actually need to set three variables: ORACLE_SID needs to be set to the value of your database name. ORACLE_HOME needs to be set to the value of the directory where your oracle binaries are installed. And PATH needs to have $ORACLE_HOME/bin added to it:

export PATH=$ORACLE_HOME/bin:$PATH

Obviously, since you are using the value of ORACLE_HOME in setting PATH, ORACLE_HOME needs to be set first.

EdStevens
  • 3,708
  • 2
  • 10
  • 18
  • How do I know where my oracle binaries are installed? – Tal Levi Nov 14 '19 at 13:37
  • @edstevens - I think for this question it is rather important to understand Docker. Docker is a platform for running containerised software, in this case an image of an installed Oracle database. The container has just enough OS to run Oracle; it's not a full-fledged environment. It's already configured to run Oracle and it's probably not a good idea to fiddle with the environment settings unless we understand both Oracle and Docker. – APC Nov 14 '19 at 14:12
  • 1
    @APC - point taken. I did say going in that I had not experience with docker, but I should have added more caveats. I see from your provided answer that enviornment changes wouldn't have helped any way, as the docker image (?) doesn't have sqlplus at all. Thanks for the feedback. :-) – EdStevens Nov 15 '19 at 15:31
0

You should connect with oracle account

su -oracle
sqlplus / as sysdba
Andromeda
  • 1,205
  • 1
  • 14
  • 21