1

I'm trying to run a simple exercise with two docker containers with oracle database 12c (store/oracle/database-enterprise:12.2.0.1). It's pretty straigthforward to run both containers but I haven't been able to connect from one to the other, what am I missing? Both containers are running on the same machine (a MacBook) and both are using the same network, I can reach them with ping

Any help would be very useful

The commands I'm using:

docker container run -d -h localdomain --name odbc -p 1521:1521 -p 5500:5500 -e DB_SID=ORCLCDB -e DB_PDB=ORCLPDB1 -e DB_DOMAIN=localdomain store/oracle/database-enterprise:12.2.0.1-slim

docker container run -d -h localdomain --name odbc2 -p 1522:1521 -p 5501:5500 -e DB_SID=ORCLCDB -e DB_PDB=ORCLPDB1 -e DB_DOMAIN=localdomain store/oracle/database-enterprise:12.2.0.1-slim
2
  1. Make sure DB is up and running with status healthy

    docker container ps
    
  2. Make sure Oracle instant client is installed on host if trying to connect from host to containers via sqlplus or any 3rd party gui tools and set up connections in tnsnames.ora on host

3̶. S̶e̶t̶ ̶u̶p̶ ̶c̶o̶n̶n̶e̶c̶t̶i̶o̶n̶s̶ ̶i̶n̶ ̶t̶n̶s̶n̶a̶m̶e̶s̶.̶o̶r̶a̶ ̶o̶n̶ ̶b̶o̶t̶h̶ ̶c̶o̶n̶t̶a̶i̶n̶e̶r̶s̶.̶ (skip this step)

  1. Make sure Oracle listener is up and running and you can find out services names on each containers by running the command

    lsnrctl status 
    
  2. You need to find out mapped ports. Execute command

    docker port orcl
    

    From my container the output is:

    $ docker port orcl
    1521/tcp -> 0.0.0.0:32769
    5500/tcp -> 0.0.0.0:32768
    
  3. You can connect directly from sqldeveloper or setup tns entries in tnsnames.ora for sqlplus client.

    Here is the screenshot connecting from sqldeveloper SqlDeveloper

    For sqlplus client on host

    #tnsname entry for container 1
    orclcdb =
    (DESCRIPTION =
      # host ipaddress and mapped port for 1521 is 32769
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.101)(PORT = 32769))
     (CONNECT_DATA =
    (SERVER = DEDICATED)
    #service name from lsnrctl status command
    (SERVICE_NAME = ORCLCDB.localdomain)
    )
    )
    
  4. Verify tnsname entries with the command from host:

    tnsping  orclcdb
    

Note

My setup was on Windows 10(host) and docker running on VM. I executed the following command to find the ipaddress of docker VM

Input:

docker-machine ls

Output:

enter image description here


Correction:

I didn't notice parameter -p 1521:1521 for the container start up command. That parameter exposes port 1521 for public. Just use container ipaddress(from docker-machine ls) and same port 1521 for sqlplus client connection from the host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.