'Java unable to get a connection to Oracle database in a docker container

I'm working with an Oracle 19c instance in a Docker container.
With DBeaver, i manage to connect to the database.
But with the following Java code, i get the following error : TNS-12535: TNS:operation timed out

        final Oracle oracle = new Oracle("jdbc:oracle:thin:@//127.0.0.1:1521/<serviceName>", "<login>", "<password>");
        OracleConnection connection = null;
        try {
            connection = oracle.getConnection();
            assertThat(connection).isNotNull();
        } finally {
            if (connection != null) {
                connection.close();
            }
        }

Here is the command i'm using to launch the Docker container : sudo docker run -d -it --name oracle19-local -e ORACLE_PDB=<serviceName> -e ORACLE_PWD=<password> -v /home/oracle/oradata19:/opt/oracle/oradata -p 1521:1521 -p 5500:5500 oracle/database:19.3.0

These are the Oracle database configuration files
tnsnames.ora :

<ServiceName in bold>= 
(DESCRIPTION = 
  (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
  (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = STARTBUILDING)
  )
)```
<br />
**listener.ora** : <br />
```LISTENER = 
(DESCRIPTION_LIST = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) 
    (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) 
  ) 
) 

DEDICATED_THROUGH_BROKER_LISTENER=ON
DIAG_ADR_ENABLED = off

Thanks for your help


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source