How do I connect to docker Oracle instance

Viewed 28985

I am following these instructions.

I have created a docker container like this:

docker run --name oracle \
-p 1521:1521  \
-e ORACLE_SID=ORASID \
-e ORACLE_PDB=ORAPDB \
-e ORACLE_PWD=F1f@f23_ \
-v /mnt_point/oradata:/home/oracle/oradata \
oracle/database:12.2.0.1-ee

The output is:

#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
Completed: alter pluggable database ORAPDB open
2017-08-07T19:16:31.190780+00:00
ORAPDB(3):CREATE SMALLFILE TABLESPACE "USERS" LOGGING  DATAFILE  '/opt/oracle/oradata/ORASID/ORAPDB/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED  EXTENT MANAGEMENT LOCAL  SEGMENT SPACE MANAGEMENT  AUTO
ORAPDB(3):Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING  DATAFILE  '/opt/oracle/oradata/ORASID/ORAPDB/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED  EXTENT MANAGEMENT LOCAL  SEGMENT SPACE MANAGEMENT  AUTO
ORAPDB(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"
ORAPDB(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2017-08-07T19:16:32.867558+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORASID/control01.ctl' SCOPE=SPFILE;
   ALTER PLUGGABLE DATABASE ORAPDB SAVE STATE
Completed:    ALTER PLUGGABLE DATABASE ORAPDB SAVE STATE

I kill it via ctrl+c. I then run:

docker start oracle
docker logs -f oracle

#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
ORAPDB(3):Undo initialization finished serial:0 start:508498668 end:508498772 diff:104 ms (0.1 seconds)
ORAPDB(3):Database Characterset for ORAPDB is AL32UTF8
ORAPDB(3):Opatch validation is skipped for PDB ORAPDB (con_id=0)
2017-08-07T19:25:39.799508+00:00
ORAPDB(3):Opening pdb with no Resource Manager plan active
Pluggable database ORAPDB opened read write
Starting background process CJQ0
Completed: ALTER DATABASE OPEN
2017-08-07T19:25:40.536753+00:00
CJQ0 started with pid=38, OS id=239
2017-08-07T19:25:42.538433+00:00
Shared IO Pool defaulting to 64MB. Trying to get it from Buffer Cache for process 77.
===========================================================
Dumping current patch information
===========================================================
No patches have been applied
===========================================================

I then attempt to connect like this:

docker exec -ti oracle sqlplus pdbadmin@ORAPDB

The result is:

ORA-12154: TNS:could not resolve the connect identifier specified

It then asks me for a username. Regardless of which user SYS, SYSTEM or PDBADMIN, I cannot connect. I have retyped the password (F1f@f23_) a multitude of times to make sure it was not a typo. Any thoughts on this would be appreciated.

6 Answers

Yes, I got the same error after setting up Oracle database in docker too.

So first check the instance is running (and look for the ORACLE_SID):

enter image description here

The Oracle SID is ORCLCDB.

If you don't have the environment set for ORACLE_SID, you get:

enter image description here

Connection failed.

But after you set your ORACLE_SID:

enter image description here

And now you no longer get the connection failure error, but a different SYSDBA instead.

Just add "/ as sysdba" to your entire sqlplus command and you are good to go.

In my case, the definition of environment variable TNS_ADMIN was causing the issue with ORA-12154. I could successfully connect to the instance inside of the XE container: sqlplus test/test@//localhost:1521/XEPDB1, but not from outside.

After removing TNS_ADMIN it worked. I think, sqlplus takes TNS_ADMIN setting, and if it exists, it takes the tnsnames.ora data to resolve the connection. But of course, the Oracle XE instance from inside docker is not listed there.

As an alternative, you could use this syntax, which works although there is a tnsnames.ora defined: sqlplus test/test@'(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XEPDB1)))'

I think you are looking for this.

  datasource:
    url: jdbc:oracle:thin:@//localhost:1521/ORCLPDB1.localdomain
    username: SYS as SYSDBA
    password: Oradoc_db1
Related