Docker Community Forums

Share and learn in the Docker community.

Can't connect to Oracle 12c from host machine

Hello everybody, I had installed docker Oracle 12c:
docker run -d -it --name OracleDB -P store/oracle/database-enterprise:12.2.0.1
then I logged into the container’s inner sqlplus to create a new user “MYUSER” for the default PDB: ORCLPDB1
docker exec -it OracleDB bash -c "source /home/oracle/.bashrc; sqlplus /nolog"
SQL>connect sys/Oradoc_db1@ORCLCDB as sysdba
BUT I can only log into Oracle’s ORCLCDB from host using mapped port, and can’t login ORCLPDB1 using user “MYUSER”, I use DBeaver. I noticed there have no “tnsnames.ora” under ‘/u01/app/oracle/product/12.2.0/dbhome_1/network/admin/’ in container’s environment and add the file by using:
docker exec -it OracleDB bash -c "vi /u01/app/oracle/product/12.2.0/dbhome_1/network/admin/tnsnames.ora"
But it doesn’t work at all.in addition , I can’t log into Oracle’s ORCLCDB from the host using sys. It says:
Connection refused, socket connect lapse 1 ms. /172.17.0.1 32769 0 1 true

How can I log from outside the container using my created user?
One more word: I can log into the inner container’s sqlplus using “MYUSER/pswd@ORCLPDB1”

If you are on a Windows system, display a Windows command prompt.
At the command prompt, type sqlplus and press the key Enter. SQL*Plus starts and prompts you for your user name.
Type your user name and press the key Enter. …
Type your password and press the key Enter.

Thank you for your reply. My docker is running on Linux Fedora version. And my host machine doesn’t install any Oracle client but a Dbeaver instead. Before I create a user at the PDB. I can use DBeaver (user: sys as dba) to connect to Oracle’s CDB in docker. But when I created tnsnames.ora in docker, my connection from outside docker was refused whether I use sys as dba or new user.

The problem was finally solved.
First, the tnsnames.ora should be Oracle Client’s config file, should not appear at Server-side(inside docker Oracle), and also not for DBeaver
Second, the key point connecting to PDB is to check it’s the service name inside docker SQLPLUS:
select con_id, name from v$services; the service name of PDB should be fully written into any connection string.
`