简体   繁体   中英

Docker - Jenkins unable to reach sonarqube (via localhost/127.0.0.1:9000)

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

在此处输入图像描述

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

在此处输入图像描述

Global Tool Configuration

在此处输入图像描述

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() 
        } 
    } 
} 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM