I faced the issue with the sonar-scanner-cli which can't connect to the SonarQube server. Scan is run from within the docker container. Docker connects to SonarQube server through proxy so I thought that it was the issue but I tried to set proxy environment variables and also pass proxy parameters to the scanner. That didn't help. Also other binaries like yum or gradle can connect to external repos without problem from the same container.
SonarQube server version: 6.7.0.33306.
13:12:28.858 INFO: Scanner configuration file: /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_2.8/sonar-scanner-2.8/conf/sonar-scanner.properties
13:12:28.869 INFO: Project root configuration file: NONE
13:12:28.937 INFO: SonarQube Scanner 2.8
13:12:28.937 INFO: Java 1.8.0_151 Oracle Corporation (64-bit)
13:12:28.937 INFO: Linux
3.10.0-693.2.2.el7.x86_64 amd64
13:12:29.854 DEBUG: keyStore is :
13:12:29.854 DEBUG: keyStore type is : jks
13:12:29.854 DEBUG: keyStore provider is :
13:12:29.854 DEBUG: init keystore
13:12:29.854 DEBUG: init keymanager of type SunX509
13:12:30.067 DEBUG: Create : /home/jenkins/.sonar/cache
13:12:30.074 INFO: User cache: /home/jenkins/.sonar/cache
13:12:30.074 DEBUG: Create : /home/jenkins/.sonar/cache/_tmp
13:12:30.075 DEBUG: Extract sonar-scanner-api-batch in temp...
13:12:30.088 DEBUG: Get bootstrap index...
13:12:30.089 DEBUG: Download: https://hostname/batch_bootstrap/index
13:12:30.133 ERROR: SonarQube server [https://hostname] can not be reached
13:12:30.133 INFO:
------------------------------------------------------------------------
13:12:30.133 INFO: EXECUTION FAILURE
13:12:30.134 INFO:
------------------------------------------------------------------------
13:12:30.134 INFO: Total time: 1.342s
13:12:30.153 INFO: Final Memory: 4M/148M
13:12:30.154 INFO:
------------------------------------------------------------------------
13:12:30.154 ERROR: Error during SonarQube Scanner execution org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:84)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:71)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:71)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:67)
at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:218)
at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:156)
at org.sonarsource.scanner.cli.Main.execute(Main.java:72)
at org.sonarsource.scanner.cli.Main.main(Main.java:61) Caused by: java.lang.IllegalStateException: Fail to download libraries from server
at org.sonarsource.scanner.api.internal.Jars.downloadFiles(Jars.java:93)
at org.sonarsource.scanner.api.internal.Jars.download(Jars.java:70)
at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:39)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:75) ... 8 more Caused by: java.net.ConnectException: Failed to connect to hostname/IP:443
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:187)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.io.RealConnection.buildConnection(RealConnection.java:170)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.io.RealConnection.connect(RealConnection.java:111)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:296)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponse(RealCall.java:243)
at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:57)
at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:113)
at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:98)
at org.sonarsource.scanner.api.internal.Jars.downloadFiles(Jars.java:78)
... 11 more