Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sqlplus on Oracle database inside a docker container?

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

like image 981
Tal Levi Avatar asked Nov 14 '19 13:11

Tal Levi


People also ask

Can I run Oracle database in Docker?

To run your Oracle Database Express Edition container image use the docker run command as follows: docker run --name <container name> \ --shm-size=1g \ -p 1521:1521 -p 8080:8080 \ -e ORACLE_PWD=<your database passwords> \ -v [<host mount point>:]/u01/app/oracle/oradata \ oracle/database:11.2.

Can a database server run inside a docker container?

In ConclusionDocker is great for running databases in a development environment! You can even use it for databases of small, non-critical projects which run on a single server. Just make sure to have regular backups (as you should in any case), and you'll be fine.


3 Answers

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:

system/oracle@//localhost:1521/xe 

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

sys/oracle@//localhost:1521/xe as sysdba
like image 160
APC Avatar answered Oct 25 '22 23:10

APC


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;"

like image 3
JayDP123 Avatar answered Oct 25 '22 23:10

JayDP123


with this, you enter the image:

docker exec -it oracle /bin/bash

after that, you can use:

sqlplus sys as sysdba
like image 2
Guillermo Solana Avatar answered Oct 25 '22 23:10

Guillermo Solana