Starting Oracle as a service inside the docker container

I build and run Oracle Database with this dockerfile that starts the Oracle instance with the command at the last line of the dockerfile.

CMD exec $ORACLE_BASE/$RUN_FILE 

The Oracle instance works, I am able to connect to it with Oracle SQL Developer, but I am unable to do

ALTER SYSTEM SET audit_trail=db SCOPE=SPFILE; 

, for example, and get the following errors:

ORA-65040: operation not allowed from within a pluggable database 65040. 00000 - "operation not allowed from within a pluggable database" *Cause: An operation was attempted that can only be performed in the root container. *Action: Switch to the root container to perform the operation. 

So, as far as I see I need to start something like sqlplus locally in the docker container and then probably restart the instance with SHUTDOWN and STARTUP commands.

What is the easiest way to do this in the container I have? Should I make Oracle start as a service inside the docker container? Is it the best alternative? (At least the service will start when the container is run and I will be able to use bash inside the container, but this requires modification and rebuilding the dockerfile). I am not an expert in linux/docker/oracle and I need to know if I am going to the right direction or not.

1 Answer

When you connect to the database from sqldeveloper you will properly get connected to the PDB (Pluggable database) so you need to change the current container (DB) to the main container

alter session set container = CDB; 

or some thing like that.

You can also create the database as a non-CDB traditional database to avoid the Pluggable DB fuzz. Just change the response file used to create the DB.

Alternative do it in sqlplus:

Access the container:

docker exec -it <your container-id/name> /bin/bash cd /opt/oracle/product/18c/dbhome_1/bin ./sqlplus sys/<your syspwd> as sysdba 

For some reason the ORACLE_SID is sometime missing and will give you a wierd

ORA-12162 TNS:net service name is incorrectly specified 

so when in the container please verify and evt. set it before accessing the DB.

env export ORACLE_SID=<your sid> 
10

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like