Home > Back-end >  Docker - Jenkins unable to reach sonarqube (via localhost/127.0.0.1:9000)
Docker - Jenkins unable to reach sonarqube (via localhost/127.0.0.1:9000)

Time:11-21

First of all, I know there are a ton of similar post on StackOverflow with regards to this issue, and I have tried the "solutions" that was provided. Which are either use the localhost IP or Sonar Docker IP as the URL in the "Configure System". But both methods does not seem to work in my case. Where did I configure wrong?

Sonar Docker command:

docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest

Jenkins Docker command:

docker run \
  --name jenkins-docker \
  --rm \
  --detach \
  --privileged \
  --network jenkins \
  --network-alias docker \
  --env DOCKER_TLS_CERTDIR=/certs \
  --volume jenkins-docker-certs:/certs/client \
  --volume jenkins-data:/var/jenkins_home \
  --publish 3000:3000 \
  --publish 2376:2376 \
  docker:dind \
  --storage-driver overlay2

Docker Network

enter image description here

Configure System - The "Secret Text" contain the token I got from SonarQube

enter image description here

Global Tool Configuration

enter image description here

Pipeline script

pipeline { 
    agent any 
    stages { 
        stage ('Checkout') { 
            steps { 
                git branch:'master', url: 'https://github.com/OWASP/Vulnerable-Web-Application.git' 
            } 
        } 
         
        stage('Code Quality Check via SonarQube') { 
           steps { 
               script { 
                def scannerHome = tool 'SonarQube'; 
                   withSonarQubeEnv('SonarQube') { 
                   sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=OWSAP -Dsonar.sources=." 
                   } 
               } 
           } 
        } 
    } 
    post { 
        always { 
            recordIssues enabledForFailure: true, tool: sonarQube() 
        } 
    } 
} 

CodePudding user response:

Try to use --network jenkins while building sonarqube container.

Or donot use --network parameter, its default to use bridge mode for both containers

Jenkins and Sonarqube should be the same network. Then try to use http://172.17.0.1:9000 or http://sonarqube:9000 if http://localhost:9000 does not work.

  • Related