Sonarqube docker-compose Failed to connect to hostname/192.168.32.3:9000

Hi,

  • SonarQube docker image version: sonarqube:8.2-community
  • Scanner version: 4.3.0.2102-linux

I’m setting up my SonarCube in my CI connecting 2 docker images, the first is my web-app with the Sonar scanner inside and the second one is the SonarQube docker image version: sonarqube:8.2-community (I have also another docker image for a postgresql database). When I try to run the sonar-scanner command from a bash file, I have the following error:

 INFO: Scanner configuration file: /root/sonar-scanner-4.3.0.2102-linux/conf/sonar-scanner.properties
 INFO: Project root configuration file: /root/sonar-project.properties
 INFO: SonarScanner 4.3.0.2102
 INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
 INFO: Linux 4.19.76+ amd64
 INFO: User cache: /root/.sonar/cache
 ERROR: SonarQube server [http://sonarqube:9000] can not be reached
 INFO: ------------------------------------------------------------------------
 INFO: EXECUTION FAILURE
 INFO: ------------------------------------------------------------------------
 INFO: Total time: 0.983s
 INFO: Final Memory: 3M/34M
 INFO: ------------------------------------------------------------------------
 ERROR: Error during SonarScanner execution
 org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
 	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
 	at java.base/java.security.AccessController.doPrivileged(Native Method)
 	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
 	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
 	at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
 	at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
 	at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
 Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
 	at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
 	at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
 	at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
 	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
 	... 7 more
 Caused by: java.net.ConnectException: Failed to connect to sonarqube/192.168.32.3:9000
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:265)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connect(RealConnection.java:183)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Transmitter.newExchange(Transmitter.java:169)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)
 	at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:114)
 	at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)
 	at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
 	... 10 more
 Caused by: java.net.ConnectException: Connection refused (Connection refused)
 	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
 	at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
 	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
 	at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
 	at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
 	at java.base/java.net.Socket.connect(Unknown Source)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.platform.Platform.connectSocket(Platform.java:130)
 	at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:263)
 	... 31 more

This is my sonar-scanner.properties file:

#----- Default SonarQube server
sonar.host.url=http://sonarqube:9000

and this is my sonar-project.properties file:

sonar.host.url=http://sonarqube:9000
#----- Project Key
sonar.projectKey=randomkey
#----- Project Name
sonar.projectName=projectname
#----- Project Version
sonar.projectVersion=1.0
#----- Source files (relative)
sonar.sources=.
sonar.language=py
sonar.sourceEncoding=UTF-8
# Test Results
 sonar.python.xunit.reportPath=nosetests.xml
# Coverage
sonar.python.coverage.reportPath=coverage.xml
sonar.python.pylint=/usr/local/bin/pylint
sonar.python.pylint_config=.pylintrc
sonar.python.pylint.reportPath=lint_report
sonar.python.bandit.reportPaths=bandit_report.json

All the docker images are in the same network and the sonarqube server docker image has the hostname: sonarqube

I can also paste the docker-compose file if needed.

Thanks.

Hi,

Welcome to the community!

Here’s your root problem:

You need to make sure your server is actually up and reachable from where you’re running analysis.

 
Ann

Hi Ann,

Thanks for your quick reply. I saw the error message, do you have any suggestion to how verify if the docker container with the sonarqube server is up and running? I don’t know something like an healthcheck endpoint to hit from the container from where the sonarqube-scanner is located for example? Any suggestion please let know.

Thanks.

@ganncamp In addition, if it could help, I tried to run a curl command from the image where there’s the sonar-scanner like -->

curl -f http://sonarqube:9000/api/system/status
curl -f -u admin:admin http://sonarqube:9000/api/system/health

but still connection refused.

error found during the startup of the server:

ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

Hello,

Thanks for sharing more data.
Are you able ping the sonarqube hostname from the scanner container?
I realise you did state the containers are on the same network however clearly something is not working here since the simple curl commands should work under normal circumstances.

I am sharing my working docker-compose sonar82_psql_jenkins_yml.txt (781 Bytes) for your reference.

Hope that helps.
Kris

Hi @Krzysztof_Jazgara,

thanks for your reply. I have the same docker files except the port that I don’t setup because I use the usual 9000. This is the error that I found during the startup:

ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

appartently it’s an issue with elastic search maybe -->

Anyone solved?

Hello,

Yes, I have seen this one before - navigate to https://docs.sonarqube.org/7.9/requirements/requirements/ for details on bumping up vm.max_map_count. Now, the question is - on which OS to set it up?
From what I remember the answer is quite tricky cause it depends on which OS you are running as a host for docker - if MacOS for instance you need to set it up at the mini VM level the Docker uses for running containers. If Linux you need to set directly on the OS layer since Docker runs natively on Linux. Try googling this out for more precise instructions - there are some articles out there on that subject.

Hope that helps.
Kris

1 Like

Hi @Krzysztof_Jazgara,

thanks for the quick reply. I saw the problem but I don’t think I have access to the host directly to execute that command. Do you have any workaround? Unfortunately, I only have access to the docker container.

Thanks,
Gianluca

Hello Gianluca,

Do you have any workaround?

There is no workaround unfortunately. The requirement at low level and low level access is needed to overcome that.

Greetings
Kris

@Krzysztof_Jazgara thanks for your reply and your help!
We can close this ticket!

This states there is not enough resource to run sonarqube on docker container due to which container keeps restarting.
Run following command on your linux terminal. This should fix your issue right away!

sudo sysctl -w vm.max_map_count=262144