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

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


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


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


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.