skip to Main Content

I am trying to learn sonarqube via docker. Below is my docker-compose.yml file. I use ipv4, localhost, sonarqube container ip but i get below error every time. I am sharing all the code here. What am I doing wrong ?

version: '3'

services:
  sonarqube:
    image: sonarqube:latest
    ports:
      - "9000:9000"
    networks:
      - sonarnet
    environment:
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
      - SONARQUBE_JDBC_USERNAME=sonar
      - SONARQUBE_JDBC_PASSWORD=sonar
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_logs:/opt/sonarqube/logs
      - sonarqube_extensions:/opt/sonarqube/extensions
    depends_on:
      - db

  db:
    image: postgres:latest
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
      - POSTGRES_DB=sonar
    volumes:
      - postgresql:/var/lib/postgresql
    networks:
      - sonarnet

  sonarscanner:
    image: sonarsource/sonar-scanner-cli
    volumes:
      - ./payment-and-transaction:/usr/src
    environment:
      - SONAR_PROJECT_KEY=payment-and-transaction
      - SONAR_HOST_URL=http://localhost:9000
      - SONAR_LOGIN="xxxxxxxxxxxxxxxxxx"
    networks:
      - sonarnet

volumes:
  sonarqube_data:
  sonarqube_logs:
  sonarqube_extensions:
  postgresql:

networks:
  sonarnet:

Below is my error logs

sonarscanner_1  | ERROR: SonarQube server [http://localhost:9000] can not be reached
sonarscanner_1  | INFO: ------------------------------------------------------------------------
sonarscanner_1  | INFO: EXECUTION FAILURE
sonarscanner_1  | INFO: ------------------------------------------------------------------------
sonarscanner_1  | INFO: Total time: 2.387s
sonarscanner_1  | INFO: Final Memory: 3M/17M
sonarscanner_1  | INFO: ------------------------------------------------------------------------
sonarscanner_1  | ERROR: Error during SonarScanner execution
sonarscanner_1  | org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
sonarscanner_1  |   at java.base/java.security.AccessController.doPrivileged(Native Method)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
sonarscanner_1  |   at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
sonarscanner_1  |   at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
sonarscanner_1  |   at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
sonarscanner_1  |   at org.sonarsource.scanner.cli.Main.main(Main.java:62)
sonarscanner_1  | Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
sonarscanner_1  |   ... 7 more
sonarscanner_1  | Caused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:265)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connect(RealConnection.java:183)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Transmitter.newExchange(Transmitter.java:169)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:115)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
sonarscanner_1  |   ... 10 more
sonarscanner_1  | Caused by: java.net.ConnectException: Connection refused (Connection refused)
sonarscanner_1  |   at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
sonarscanner_1  |   at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
sonarscanner_1  |   at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
sonarscanner_1  |   at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
sonarscanner_1  |   at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
sonarscanner_1  |   at java.base/java.net.Socket.connect(Socket.java:609)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.platform.Platform.connectSocket(Platform.java:130)
sonarscanner_1  |   at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:263)
sonarscanner_1  |   ... 31 more
sonarscanner_1  | ERROR: 
sonarscanner_1  | ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

I am using below command to run all this

docker-compose up

2

Answers


  1. Something is worng with your setup.I will reproduce line by line,you can add later docker-compose by yourself
    First step

    docker pull sonarqube
    

    Second,make your network

    docker network create sonarnet
    

    Then,db

    docker run -d --name sonar-db --network sonarnet -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -e POSTGRES_DB=sonar postgres:9.6
    

    At the very end

    docker run -d --name sonar -p 9000:9000 --network sonarnet -e SONARQUBE_JDBC_URL=jdbc:postgresql://sonar-db:5432/sonar -e SONAR_JDBC_USERNAME=sonar -e SONAR_JDBC_PASSWORD=sonar sonarqube
    

    Check your http://localhost:9000/

    admin/admin and you should be able to log in.

    enter image description here

    Try this for sonarsource

    docker run \
        --rm \
        -e SONAR_HOST_URL="http://localhost:9000/" \
        -e SONAR_LOGIN="yourToken" \
        -v "${YOUR_REPO}:/home/dir/src" \
        sonarsource/sonar-scanner-cli
    
    Login or Signup to reply.
  2. I think there is an issue with your SONAR_HOST_URL=http://localhost:9000 in your sonarscanner container as your container cannot access process running on local machine via localhost as the localhost will be referring to your container, not your machine, so you cannot use localhost:9000 rather use sonarqube:9000 to access via container or host.docker.internal:9000 to access via your local machine

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search