Windows – Cannot connect to Oracle 19 instance running in a container under Ubuntu 20.04 via WSL2 on Docker for Windows

dockeroraclewindows

Here is my docker-compose.yml file:

version: '3.7'

services:

  database:
    image: scgain.azurecr.io/databases/${IMAGE_NAME}
    environment:
      - ORACLE_SID=${SID}
      - ORACLE_PDB=${PDB}
      - ORACLE_PWD=somepassword
      - ORACLE_CHARACTERSET=WE8MSWIN1252
    volumes:
      - ${ORACLE_HOST_DIR}oradata:/opt/oracle/oradata # persistent oracle database data
      - ${ORACLE_HOST_DIR}data-bridge:/data-bridge    # share data with the running container
    ports:
      - 1521:1521
      - 8080:8080
      - 5500:5500

and here the corresponding .env file:

IMAGE_NAME=oracle-19-e
SID=ORCL19CDB
PDB=ORCL19PDB1
ORACLE_HOST_DIR=D:\src\oracle\

When I run this container in Windows via PowerShell, I can connect to the Oracle instance just fine via SQL Developer (through hostname localhost and port 1521) and with my app using this connection string:

Host=localhost;Port=1521;User ID=someuser;Password=somepassword;Service Name=ORCL19PDB1;Direct=true

When I run it instead in WSL2 (Ubuntu 20,04) I can browse the mapped volumes inside the container. I can connect to the instance inside the container via sqlplus and see all the schemas and tables, but trying to connect to it through SQL Developer gives me a Code 17002 error (unable to establish connection). Also, my app throws an analogous exception that it cannot find the database.

Here is the .env file for Linux:

IMAGE_NAME=oracle-19-e
SID=ORCL19CDB
PDB=ORCL19PDB1
ORACLE_HOST_DIR=/mnt/d/src/oracle/

I checked with lsnrctl status that the TNS listener is running inside the container.

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 03-NOV-2020 20:31:27

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                03-NOV-2020 19:50:01
Uptime                    0 days 0 hr. 41 min. 26 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/32c1b8c48d42/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=32c1b8c48d42)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/ORCL19CDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "ORCL19CDB" has 1 instance(s).
  Instance "ORCL19CDB", status READY, has 1 handler(s) for this service...
Service "ORCL19CDBXDB" has 1 instance(s).
  Instance "ORCL19CDB", status READY, has 1 handler(s) for this service...
Service "ab0e9cc3a7c10befe053020016acb4c7" has 1 instance(s).
  Instance "ORCL19CDB", status READY, has 1 handler(s) for this service...
Service "orcl19pdb1" has 1 instance(s).
  Instance "ORCL19CDB", status READY, has 1 handler(s) for this service...
The command completed successfully

What do I need to do to connect to the db outside of its container when it is running in WSL2?

Best Answer

Well, I found the culprit. The port assignment

      - 8080:8080

is not needed (it was legacy from previous work), and once I take it out, I can connect via SQL Developer and my app is happy as well. Not sure I understand the reason, but for now I am back in business.