Unable to connect to oracle Database from docker image

Make sure to tell us:

  • What version are you upgrading from?
    8.9 to 9.9
  • System information (Operating system, Java version, Database provider/version)
    Linux, Docker image and Oracle database
  • What’s the issue you’re facing?
    We have currently Sonarqube 8.9 community version running in our environment but it’s running on Server, but we are doing a POC to move it to Docker, when i have modified the sonarqube official community image and added sonar.properties file to which includes our DB configuration and LDAP configurations, when starting up the image, the container is not able to connect to Database. We are seeing the below error, seems like DNS resolution failure.
    I would expect it should honor the docker hosted resolve.conf file which is resolving the DB hostname just fine. Any recommendations would be appericiated?
2023.07.25 16:48:47 WARN  web[][o.s.c.a.AnnotationConfigApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@503ecb24-org.sonar.db.DefaultDatabase': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Fail to connect to database
2023.07.25 16:48:47 ERROR web[][o.s.s.p.PlatformImpl] Web server startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@503ecb24-org.sonar.db.DefaultDatabase': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Fail to connect to database
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:920)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:187)
        at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:80)
        at org.sonar.server.platform.platformlevel.PlatformLevel1.start(PlatformLevel1.java:164)
        at org.sonar.server.platform.PlatformImpl.start(PlatformImpl.java:196)
        at org.sonar.server.platform.PlatformImpl.startLevel1Container(PlatformImpl.java:162)
        at org.sonar.server.platform.PlatformImpl.init(PlatformImpl.java:76)
        at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:43)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4494)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4946)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:871)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:795)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:871)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:249)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:428)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:917)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486)
        at org.sonar.server.app.EmbeddedTomcat.start(EmbeddedTomcat.java:72)
        at org.sonar.server.app.WebServer.start(WebServer.java:55)
        at org.sonar.process.ProcessEntryPoint.launch(ProcessEntryPoint.java:97)
        at org.sonar.process.ProcessEntryPoint.launch(ProcessEntryPoint.java:81)
        at org.sonar.server.app.WebServer.main(WebServer.java:104)
Caused by: java.lang.IllegalStateException: Fail to connect to database
        at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:130)
        at org.sonar.core.platform.StartableBeanPostProcessor.postProcessBeforeInitialization(StartableBeanPostProcessor.java:33)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
        ... 44 common frames omitted
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: ORA-17868: Unknown host specified.: ittools-devl.dhw.state.id.us: Temporary failure in name resolution
        at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:596)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:582)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
        at org.sonar.db.DefaultDatabase.createHikariDataSource(DefaultDatabase.java:159)
        at org.sonar.db.DefaultDatabase.initDataSource(DefaultDatabase.java:148)
        at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:126)
        ... 48 common frames omitted
Caused by: java.sql.SQLException: ORA-17868: Unknown host specified.: ittools-devl.dhw.state.id.us: Temporary failure in name resolution
        at oracle.jdbc.driver.T4CConnection.handleLogonNetException(T4CConnection.java:1099)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:879)
        at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:1132)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:104)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:837)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:664)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
        ... 53 common frames omitted
Caused by: oracle.net.ns.NetException: ORA-17868: Unknown host specified.: ittools-devl.dhw.state.id.us: Temporary failure in name resolution
        at oracle.net.resolver.NavAddress.parseAddressParamsAndNavigate(NavAddress.java:208)
        at oracle.net.resolver.NavAddress.navigate(NavAddress.java:83)
        at oracle.net.resolver.NavDescription.navigate(NavDescription.java:214)
        at oracle.net.resolver.NavServiceAlias.navigate(NavServiceAlias.java:61)
        at oracle.net.resolver.AddrResolution.resolveAddrTree(AddrResolution.java:1106)
        at oracle.net.resolver.AddrResolution.resolveTNSAddress(AddrResolution.java:922)
        at oracle.net.resolver.AddrResolution.initConnStrategy(AddrResolution.java:613)
        at oracle.net.resolver.AddrResolution.<init>(AddrResolution.java:430)
        at oracle.net.ns.NSProtocol.<init>(NSProtocol.java:242)
        at oracle.net.ns.NSProtocolNIO.<init>(NSProtocolNIO.java:143)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:793)
        ... 62 common frames omitted

Hi,

Did you copy the DB setting values directly from your old instance into your Docker configuration, or were any changes made?

 
Ann

Hello Ann,
I’m using the DB setting values same as my old instance. I have copied old sonar.properties file into docker and passing values in that file. I jhave also tried passing values with option “-e” as mentioned in documentation neither worked , both failing with same error.

Hi,

To verify, you used the envvar names listed in the docs? And put the driver in the right directory?

You said something about a sonar.properties file, but I don’t believe that’s picked up by a Docker deployment.

 
Ann

Hello Ann, Thanks for replying
I’m following this documentation[1] , I have tried to pass DB arguments in docker run command and also tried with putting them in sonar.properties, for both ways getting the same error. I believe sonar.properties is also picked by docker as i can see the JDBC URL is getting printed in logs during the start up with sonar.properties. Yes the driver is also in correct directory.
With the above error i believe the DNS is not able to resolve even though the the DNS getting resolved on that docker host. Ideally it should honor the resolv.conf file from that docker host(where sonarqube container is running)

[1] Install the server

Dear @rajeshekv,

thanks for posting about your issue and building a POC for using SQ as docker container :smiley:

May I ask you for more details about the exact properties that you use? It would be great to have the full command line that you use for creating the container, including arguments or any supplementary files (e.g., ) that you inject.

Furthermore, you host the DB on a separate server (which is great!). How is the DB made available to the SQ docker container? Via the internet? Can you ping the db from within the container? Are you able to reach it?

We were trying to replicate your issue trying to mimic your setup (using postgresql instead of oracle) without success.

Hello, thanks for the reply.
Here is the command i’m using
docker run -d --privileged --name sonarqube -p 9000:9000 -e SONAR_JDBC_URL='jdbc:oracle:thin:@(description= (retry_count=2)(retry_delay=3)(address=(protocol=tcp)(port=1521)(host=ittools-devl.dhw.state.id.us))(connect_data=(service_name=)))’ -e SONAR_JDBC_USERNAME= -e SONAR_JDBC_PASSWORD=***** -v /opt/sonarq/sonarqube-9.9.1/data:/opt/sonarqube/data -v sonarqube_extensions:/opt/sonarqube/extensions -v sonarqube_logs:/opt/sonarqube/logs c7118af4f66b

and yes i’m able to ping the database host with DNS name (ittools-devl.dhw.state.id.us) from inside the container . We have everything on-prem and everything is with in our corporate network

Hi @rajeshekv,

thanks for sending more details on your deployment.

We think it’s worth investigating the DNS resolution a little bit more and we came up with a few suggestions/trials to properly troubleshoot this. Can you try to perform each of these separately and give us feedback on each?

  1. Although this seems to contradict your ping, we could force the DNS resolution in your docker container? When running the container, we could add an extra argument --add-host ittools-devl.dhw.state.id.us:X.X.X.X , where X.X.X.X is the IP corresponding to ittools-devl.dhw.state.id.us. (Please get it from within the container using dig ittools-devl.dhw.state.id.us). In addition to that, please make sure to bind your container to the local network using --network host
  2. To isolate any possible issues coming from using an Oracle db, could you please host a simple Postgresql db on the same server and try to use the SQ docker image to connect to it? Do you hit the same name resolution issues?
  3. If we don’t make any progress with all the above approaches, could you please try using sonarqube: 8.9-community and check if you hit the same issue?
1 Like

Hello Carmine,

By adding “–network host” to the start command it started fine after that.
Here is our updated start command looks -
docker run --rm --privileged -t -p 9000:9000 --network host -v /opt/sonarq/sonarqube-9.9.1/extensions:/opt/sonarqube/extensions -v /opt/sonarq/sonarqube-9.9.1/data:/opt/sonarqube/data -v /opt/sonarq/dev-sonarqlogs:/opt/sonarqube/logs -v /opt/sonarq/sonarqube-9.9.1/conf:/opt/sonarqube/conf 7f0aea7b1dc5

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.