Fail to connect to database with any 8.0-* docker images

Dear community,

I’m looking for some support to install a 8.0-developer-beta docker image on ubuntu.

Using https://github.com/SonarSource/docker-sonarqube/blob/master/recipes/docker-compose-postgres-example.yml ( 7f7b164 as a reference, I’m able to fully install and run a sonarqube 7.9.1 using “image: sonarqube”.
However, changing the sonarqube image to: “image: sonarqube:8.0-developer-beta”, the image fails to start with the following stack (same error with any 8.0-* image)

2019.12.17 00:33:28 INFO app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sq/temp
2019.12.17 00:33:28 INFO app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2019.12.17 00:33:28 INFO app[][o.s.a.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/sq/elasticsearch]: /opt/sq/elasticsearch/bin/elasticsearch
2019.12.17 00:33:28 INFO app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
2019.12.17 00:33:29 INFO app[][o.e.p.PluginsService] no modules loaded
2019.12.17 00:33:29 INFO app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019.12.17 00:33:31 INFO es[][o.e.e.NodeEnvironment] using [1] data paths, mounts [[/opt/sonarqube/data (/dev/sda1)]], net usable_space [37.3gb], net total_space [77.7gb], types [ext4]
2019.12.17 00:33:31 INFO es[][o.e.e.NodeEnvironment] heap size [494.9mb], compressed ordinary object pointers [true]
2019.12.17 00:33:31 INFO es[][o.e.n.Node] node name [sonarqube], node ID [wTaKD-b1RhKbKNVwklhS_Q]
2019.12.17 00:33:31 INFO es[][o.e.n.Node] version[6.8.0], pid[33], build[default/tar/65b6179/2019-05-15T20:06:13.172855Z], OS[Linux/4.4.0-98-generic/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/11.0.5/11.0.5+10]
2019.12.17 00:33:31 INFO es[][o.e.n.Node] JVM arguments [-XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/opt/sq/temp, -XX:ErrorFile=../logs/es_hs_err_pid%p.log, -Des.enforce.bootstrap.checks=true, -Xmx512m, -Xms512m, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/opt/sq/elasticsearch, -Des.path.conf=/opt/sq/temp/conf/es, -Des.distribution.flavor=default, -Des.distribution.type=tar]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] loaded module [analysis-common]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] loaded module [lang-painless]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] loaded module [mapper-extras]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] loaded module [parent-join]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] loaded module [percolator]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] loaded module [reindex]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] loaded module [repository-url]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] loaded module [transport-netty4]
2019.12.17 00:33:32 INFO es[][o.e.p.PluginsService] no plugins loaded
2019.12.17 00:33:34 WARN es[][o.e.d.c.s.Settings] [http.enabled] setting was deprecated in Elasticsearch and will be removed in a future release! See the breaking changes documentation for the next major version.
2019.12.17 00:33:35 INFO es[][o.e.d.DiscoveryModule] using discovery type [zen] and host providers [settings]
2019.12.17 00:33:36 INFO es[][o.e.n.Node] initialized
2019.12.17 00:33:36 INFO es[][o.e.n.Node] starting ...
2019.12.17 00:33:36 INFO es[][o.e.t.TransportService] publish_address {127.0.0.1:9001}, bound_addresses {127.0.0.1:9001}
2019.12.17 00:33:36 INFO es[][o.e.b.BootstrapChecks] explicitly enforcing bootstrap checks
2019.12.17 00:33:39 INFO es[][o.e.c.s.MasterService] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {sonarqube}{wTaKD-b1RhKbKNVwklhS_Q}{iQQexruDT1aL26NsPBGMrw}{127.0.0.1}{127.0.0.1:9001}{rack_id=sonarqube}
2019.12.17 00:33:39 INFO es[][o.e.c.s.ClusterApplierService] new_master {sonarqube}{wTaKD-b1RhKbKNVwklhS_Q}{iQQexruDT1aL26NsPBGMrw}{127.0.0.1}{127.0.0.1:9001}{rack_id=sonarqube}, reason: apply cluster state (from master [master {sonarqube}{wTaKD-b1RhKbKNVwklhS_Q}{iQQexruDT1aL26NsPBGMrw}{127.0.0.1}{127.0.0.1:9001}{rack_id=sonarqube} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
2019.12.17 00:33:39 INFO es[][o.e.n.Node] started
2019.12.17 00:33:39 INFO es[][o.e.g.GatewayService] recovered [7] indices into cluster_state
2019.12.17 00:33:40 INFO es[][o.e.c.r.a.AllocationService] Cluster health status changed from [RED] to [GREEN] (reason: [shards started [[metadatas][0]] ...]).
2019.12.17 00:33:41 INFO app[][o.s.a.SchedulerImpl] Process[es] is up
2019.12.17 00:33:41 INFO app[][o.s.a.ProcessLauncherImpl] Launch process[[key='web', ipcIndex=2, logFilenamePrefix=web]] from [/opt/sq]: /usr/local/openjdk-11/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sq/temp --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dhttp.nonProxyHosts=localhost|127.*|[::1] -cp ./lib/common/*:/opt/sq/lib/jdbc/postgresql/postgresql-42.2.5.jar org.sonar.server.app.WebServer /opt/sq/temp/sq-process3098921074192952193properties
2019.12.17 00:33:41 INFO web[][o.s.p.ProcessEntryPoint] Starting web
2019.12.17 00:33:42 INFO web[][o.a.t.u.n.NioSelectorPool] Using a shared selector for servlet write/read
2019.12.17 00:33:43 INFO web[][o.s.c.e.CoreExtensionsLoader] Loaded core extensions: developer-edition, developer-scanner, developer-server, license
2019.12.17 00:33:43 INFO web[][o.e.p.PluginsService] no modules loaded
2019.12.17 00:33:43 INFO web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2019.12.17 00:33:43 INFO web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2019.12.17 00:33:43 INFO web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019.12.17 00:33:44 INFO web[][o.s.s.e.EsClientProvider] Connected to local Elasticsearch: [127.0.0.1:9001]
2019.12.17 00:33:44 INFO web[][o.s.s.p.LogServerVersion] SonarQube Server / 8.0.0.29455 / f869d840f12a4dfa69533e17d3b27558617a7f82
2019.12.17 00:33:44 INFO web[][o.sonar.db.Database] Create JDBC data source for jdbc:postgresql://db:5432/sonar
2019.12.17 00:33:44 ERROR web[][o.s.s.p.PlatformImpl] Web server startup failed
java.lang.IllegalStateException: Fail to connect to database
at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:87)
at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
at org.picocontainer.behaviors.Stored.start(Stored.java:110)
at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
at org.sonar.server.platform.platformlevel.PlatformLevel1.start(PlatformLevel1.java:164)
at org.sonar.server.platform.PlatformImpl.start(PlatformImpl.java:213)
at org.sonar.server.platform.PlatformImpl.startLevel1Container(PlatformImpl.java:172)
at org.sonar.server.platform.PlatformImpl.init(PlatformImpl.java:86)
at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:43)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4770)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5236)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1423)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1413)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').
at org.sonar.db.DefaultDatabase.checkConnection(DefaultDatabase.java:119)
at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:84)
... 24 common frames omitted

Reporting that as a bug as there is no explicit comment to define that the docker-compose-postgres-example.yml should only work for a 7.9.1 image.

Is there any specific compose conf. file to use for the 8.0-* images or is it suppose to work for all available images?

Thanks for your support.

Hello,

I guess you saw that the error is obvious:

And I think the stack says more than that, likely that no PostgreSQL user name specified in startup packet, right?
The 7th dockerfile defines environement variables matching what the PostgreSQL image creates (sonar:sonar). The 8th Dockerfile don’t do that to ease the customization of this (see how the run.sh uses it). What it means is that you have to specify in your docker-compose.yml these value as environement variables, typically:

environment:
  - sonar.jdbc.url=jdbc:postgresql://dbsq80:5432/sonar
  - sonar.jdbc.username=sonar
  - sonar.jdbc.password=sonar

Also, be careful if you use the same volumes and not new ones, you will have to upgrade the DB and make sure used extensions matches the plugin matrix.

Cheers

2 Likes

Thanks a lot for your response. Worked perfectly well.