How to get SonarQube (running in docker container) to connect to localhost:9000 from Jenkins Pipeline?

Multi tool use
Multi tool use





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am running SonarQube on both java and javascript code inside a CentOS VM. I pulled the sonarqube docker image and am running the container. I exposed port 9000 and am able to open up localhost:9000 and interact with the sonarqube gui. When I run the sonar-scanner from the command line on the JavaScript code using this command:



sonar-scanner -Dsonar.projectKey=javascript_code -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=admin 


I get a fully analyzed project. As well as the JavaScript code I can run it on the Java code using the maven build. Both work correctly from the command line.



When I add it into a Jenkins Pipeline I do the exact same commands and get the following:



Error: SonarQube server [http://localhost:9000] can not be reached

Caused by: Fail to get bootstrap index from server

Caused by: Failed to connect to localhost:9000

Caused by: Connection refused (Connection refused)


I also tried when starting the container to use --network="host" instead of publishing port 9000, but it still does not connect from the Jenkins Pipeline. Everything works correctly when I am running the commands from the Command Line, just when I try to put it into a Jenkins Pipeline.



Any suggestions on how to fix this? Thanks.



*Edit: Using the sonarqube plugin I was able to get my analysis to run as a Jenkins Job. However, when I try to add the analysis into the pipeline I get the same SonarQube server cannot be reached error. It says it skips my project because the project has been banned form the build due to previous failures and gives me this error message:



[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project sonarqubeproj: 
Unable to execute SonarQube: Fail to get bootstrap index from server: unexpected end of stream on Connection{localhost:9000, proxy=DIRECT hostAddress=localhost/127.0.0.1:9000 cipherSuite=none protocol=http/1.1}: n not found: limit=0 content=… -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project feedback-tool-ui: Unable to execute SonarQube









share|improve this question

























  • Is the pipeline using another user not known by SonarQube?

    – Jeroen Heier
    Jan 4 at 19:27











  • how do you run jenkins? i assume you are using a docker image for jenkins? might be that localhost called from this jenkins docker image is just referencing the docker image, and not the sonarqube image. i am not sure, how you spin up your docker images, but if you use docker-compose you could easily use the provided name instead of localhost

    – Simon Schrottner
    Jan 7 at 7:52











  • The pipeline is using a user known by SonarQube. I am using the docker image for jenkins, but I didn't use docker-compose when starting it up. Do you suggest I use the ip address and not localhost?

    – user10620554
    Jan 7 at 14:26











  • yes that could solve the issue too :D

    – Simon Schrottner
    Jan 7 at 15:25


















0















I am running SonarQube on both java and javascript code inside a CentOS VM. I pulled the sonarqube docker image and am running the container. I exposed port 9000 and am able to open up localhost:9000 and interact with the sonarqube gui. When I run the sonar-scanner from the command line on the JavaScript code using this command:



sonar-scanner -Dsonar.projectKey=javascript_code -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=admin 


I get a fully analyzed project. As well as the JavaScript code I can run it on the Java code using the maven build. Both work correctly from the command line.



When I add it into a Jenkins Pipeline I do the exact same commands and get the following:



Error: SonarQube server [http://localhost:9000] can not be reached

Caused by: Fail to get bootstrap index from server

Caused by: Failed to connect to localhost:9000

Caused by: Connection refused (Connection refused)


I also tried when starting the container to use --network="host" instead of publishing port 9000, but it still does not connect from the Jenkins Pipeline. Everything works correctly when I am running the commands from the Command Line, just when I try to put it into a Jenkins Pipeline.



Any suggestions on how to fix this? Thanks.



*Edit: Using the sonarqube plugin I was able to get my analysis to run as a Jenkins Job. However, when I try to add the analysis into the pipeline I get the same SonarQube server cannot be reached error. It says it skips my project because the project has been banned form the build due to previous failures and gives me this error message:



[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project sonarqubeproj: 
Unable to execute SonarQube: Fail to get bootstrap index from server: unexpected end of stream on Connection{localhost:9000, proxy=DIRECT hostAddress=localhost/127.0.0.1:9000 cipherSuite=none protocol=http/1.1}: n not found: limit=0 content=… -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project feedback-tool-ui: Unable to execute SonarQube









share|improve this question

























  • Is the pipeline using another user not known by SonarQube?

    – Jeroen Heier
    Jan 4 at 19:27











  • how do you run jenkins? i assume you are using a docker image for jenkins? might be that localhost called from this jenkins docker image is just referencing the docker image, and not the sonarqube image. i am not sure, how you spin up your docker images, but if you use docker-compose you could easily use the provided name instead of localhost

    – Simon Schrottner
    Jan 7 at 7:52











  • The pipeline is using a user known by SonarQube. I am using the docker image for jenkins, but I didn't use docker-compose when starting it up. Do you suggest I use the ip address and not localhost?

    – user10620554
    Jan 7 at 14:26











  • yes that could solve the issue too :D

    – Simon Schrottner
    Jan 7 at 15:25














0












0








0








I am running SonarQube on both java and javascript code inside a CentOS VM. I pulled the sonarqube docker image and am running the container. I exposed port 9000 and am able to open up localhost:9000 and interact with the sonarqube gui. When I run the sonar-scanner from the command line on the JavaScript code using this command:



sonar-scanner -Dsonar.projectKey=javascript_code -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=admin 


I get a fully analyzed project. As well as the JavaScript code I can run it on the Java code using the maven build. Both work correctly from the command line.



When I add it into a Jenkins Pipeline I do the exact same commands and get the following:



Error: SonarQube server [http://localhost:9000] can not be reached

Caused by: Fail to get bootstrap index from server

Caused by: Failed to connect to localhost:9000

Caused by: Connection refused (Connection refused)


I also tried when starting the container to use --network="host" instead of publishing port 9000, but it still does not connect from the Jenkins Pipeline. Everything works correctly when I am running the commands from the Command Line, just when I try to put it into a Jenkins Pipeline.



Any suggestions on how to fix this? Thanks.



*Edit: Using the sonarqube plugin I was able to get my analysis to run as a Jenkins Job. However, when I try to add the analysis into the pipeline I get the same SonarQube server cannot be reached error. It says it skips my project because the project has been banned form the build due to previous failures and gives me this error message:



[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project sonarqubeproj: 
Unable to execute SonarQube: Fail to get bootstrap index from server: unexpected end of stream on Connection{localhost:9000, proxy=DIRECT hostAddress=localhost/127.0.0.1:9000 cipherSuite=none protocol=http/1.1}: n not found: limit=0 content=… -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project feedback-tool-ui: Unable to execute SonarQube









share|improve this question
















I am running SonarQube on both java and javascript code inside a CentOS VM. I pulled the sonarqube docker image and am running the container. I exposed port 9000 and am able to open up localhost:9000 and interact with the sonarqube gui. When I run the sonar-scanner from the command line on the JavaScript code using this command:



sonar-scanner -Dsonar.projectKey=javascript_code -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=admin 


I get a fully analyzed project. As well as the JavaScript code I can run it on the Java code using the maven build. Both work correctly from the command line.



When I add it into a Jenkins Pipeline I do the exact same commands and get the following:



Error: SonarQube server [http://localhost:9000] can not be reached

Caused by: Fail to get bootstrap index from server

Caused by: Failed to connect to localhost:9000

Caused by: Connection refused (Connection refused)


I also tried when starting the container to use --network="host" instead of publishing port 9000, but it still does not connect from the Jenkins Pipeline. Everything works correctly when I am running the commands from the Command Line, just when I try to put it into a Jenkins Pipeline.



Any suggestions on how to fix this? Thanks.



*Edit: Using the sonarqube plugin I was able to get my analysis to run as a Jenkins Job. However, when I try to add the analysis into the pipeline I get the same SonarQube server cannot be reached error. It says it skips my project because the project has been banned form the build due to previous failures and gives me this error message:



[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project sonarqubeproj: 
Unable to execute SonarQube: Fail to get bootstrap index from server: unexpected end of stream on Connection{localhost:9000, proxy=DIRECT hostAddress=localhost/127.0.0.1:9000 cipherSuite=none protocol=http/1.1}: n not found: limit=0 content=… -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project feedback-tool-ui: Unable to execute SonarQube






docker jenkins networking sonarqube localhost






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 7 at 14:31







user10620554

















asked Jan 3 at 21:34









user10620554user10620554

32




32













  • Is the pipeline using another user not known by SonarQube?

    – Jeroen Heier
    Jan 4 at 19:27











  • how do you run jenkins? i assume you are using a docker image for jenkins? might be that localhost called from this jenkins docker image is just referencing the docker image, and not the sonarqube image. i am not sure, how you spin up your docker images, but if you use docker-compose you could easily use the provided name instead of localhost

    – Simon Schrottner
    Jan 7 at 7:52











  • The pipeline is using a user known by SonarQube. I am using the docker image for jenkins, but I didn't use docker-compose when starting it up. Do you suggest I use the ip address and not localhost?

    – user10620554
    Jan 7 at 14:26











  • yes that could solve the issue too :D

    – Simon Schrottner
    Jan 7 at 15:25



















  • Is the pipeline using another user not known by SonarQube?

    – Jeroen Heier
    Jan 4 at 19:27











  • how do you run jenkins? i assume you are using a docker image for jenkins? might be that localhost called from this jenkins docker image is just referencing the docker image, and not the sonarqube image. i am not sure, how you spin up your docker images, but if you use docker-compose you could easily use the provided name instead of localhost

    – Simon Schrottner
    Jan 7 at 7:52











  • The pipeline is using a user known by SonarQube. I am using the docker image for jenkins, but I didn't use docker-compose when starting it up. Do you suggest I use the ip address and not localhost?

    – user10620554
    Jan 7 at 14:26











  • yes that could solve the issue too :D

    – Simon Schrottner
    Jan 7 at 15:25

















Is the pipeline using another user not known by SonarQube?

– Jeroen Heier
Jan 4 at 19:27





Is the pipeline using another user not known by SonarQube?

– Jeroen Heier
Jan 4 at 19:27













how do you run jenkins? i assume you are using a docker image for jenkins? might be that localhost called from this jenkins docker image is just referencing the docker image, and not the sonarqube image. i am not sure, how you spin up your docker images, but if you use docker-compose you could easily use the provided name instead of localhost

– Simon Schrottner
Jan 7 at 7:52





how do you run jenkins? i assume you are using a docker image for jenkins? might be that localhost called from this jenkins docker image is just referencing the docker image, and not the sonarqube image. i am not sure, how you spin up your docker images, but if you use docker-compose you could easily use the provided name instead of localhost

– Simon Schrottner
Jan 7 at 7:52













The pipeline is using a user known by SonarQube. I am using the docker image for jenkins, but I didn't use docker-compose when starting it up. Do you suggest I use the ip address and not localhost?

– user10620554
Jan 7 at 14:26





The pipeline is using a user known by SonarQube. I am using the docker image for jenkins, but I didn't use docker-compose when starting it up. Do you suggest I use the ip address and not localhost?

– user10620554
Jan 7 at 14:26













yes that could solve the issue too :D

– Simon Schrottner
Jan 7 at 15:25





yes that could solve the issue too :D

– Simon Schrottner
Jan 7 at 15:25












1 Answer
1






active

oldest

votes


















0














The problem you are facing is most likely related to how you run jenkins.



I assume you also run jenkins via docker. this means that in the context of jenkins, localhost is not your host system, but the jenkins container. This means you need to adapt your sonarqube-url to reference the host system.



Therefore you have multiple options:




  1. use the public ip of the host system

  2. use the docker ip of the host system

  3. resolve the ip via dns. docker has an internal DNS and if those container run in the same network, you can normally reach them by containername.


sidenote:
i am not sure if you are using docker-compose or kubernetes, but if you are not using it, you might also want to dive into docker-compose as it is just a simple yaml-config in which you can easily start up servers.






share|improve this answer
























  • I agree that it has to be something how jenkins is run...I tried doing what you suggested. For the public ip of the host I got the same error as above and when I tried the docker ip of host system I got a connection refused error. It doesn't let me curl the docker ip from inside the jenkins container or the pipeline so I think it is an issue with how jenkins is interacting with the docker network. I am going to try to see if I can run jenkins in another way to get it to work

    – user10620554
    Jan 7 at 18:17














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030106%2fhow-to-get-sonarqube-running-in-docker-container-to-connect-to-localhost9000%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The problem you are facing is most likely related to how you run jenkins.



I assume you also run jenkins via docker. this means that in the context of jenkins, localhost is not your host system, but the jenkins container. This means you need to adapt your sonarqube-url to reference the host system.



Therefore you have multiple options:




  1. use the public ip of the host system

  2. use the docker ip of the host system

  3. resolve the ip via dns. docker has an internal DNS and if those container run in the same network, you can normally reach them by containername.


sidenote:
i am not sure if you are using docker-compose or kubernetes, but if you are not using it, you might also want to dive into docker-compose as it is just a simple yaml-config in which you can easily start up servers.






share|improve this answer
























  • I agree that it has to be something how jenkins is run...I tried doing what you suggested. For the public ip of the host I got the same error as above and when I tried the docker ip of host system I got a connection refused error. It doesn't let me curl the docker ip from inside the jenkins container or the pipeline so I think it is an issue with how jenkins is interacting with the docker network. I am going to try to see if I can run jenkins in another way to get it to work

    – user10620554
    Jan 7 at 18:17


















0














The problem you are facing is most likely related to how you run jenkins.



I assume you also run jenkins via docker. this means that in the context of jenkins, localhost is not your host system, but the jenkins container. This means you need to adapt your sonarqube-url to reference the host system.



Therefore you have multiple options:




  1. use the public ip of the host system

  2. use the docker ip of the host system

  3. resolve the ip via dns. docker has an internal DNS and if those container run in the same network, you can normally reach them by containername.


sidenote:
i am not sure if you are using docker-compose or kubernetes, but if you are not using it, you might also want to dive into docker-compose as it is just a simple yaml-config in which you can easily start up servers.






share|improve this answer
























  • I agree that it has to be something how jenkins is run...I tried doing what you suggested. For the public ip of the host I got the same error as above and when I tried the docker ip of host system I got a connection refused error. It doesn't let me curl the docker ip from inside the jenkins container or the pipeline so I think it is an issue with how jenkins is interacting with the docker network. I am going to try to see if I can run jenkins in another way to get it to work

    – user10620554
    Jan 7 at 18:17
















0












0








0







The problem you are facing is most likely related to how you run jenkins.



I assume you also run jenkins via docker. this means that in the context of jenkins, localhost is not your host system, but the jenkins container. This means you need to adapt your sonarqube-url to reference the host system.



Therefore you have multiple options:




  1. use the public ip of the host system

  2. use the docker ip of the host system

  3. resolve the ip via dns. docker has an internal DNS and if those container run in the same network, you can normally reach them by containername.


sidenote:
i am not sure if you are using docker-compose or kubernetes, but if you are not using it, you might also want to dive into docker-compose as it is just a simple yaml-config in which you can easily start up servers.






share|improve this answer













The problem you are facing is most likely related to how you run jenkins.



I assume you also run jenkins via docker. this means that in the context of jenkins, localhost is not your host system, but the jenkins container. This means you need to adapt your sonarqube-url to reference the host system.



Therefore you have multiple options:




  1. use the public ip of the host system

  2. use the docker ip of the host system

  3. resolve the ip via dns. docker has an internal DNS and if those container run in the same network, you can normally reach them by containername.


sidenote:
i am not sure if you are using docker-compose or kubernetes, but if you are not using it, you might also want to dive into docker-compose as it is just a simple yaml-config in which you can easily start up servers.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 7 at 15:38









Simon SchrottnerSimon Schrottner

8861920




8861920













  • I agree that it has to be something how jenkins is run...I tried doing what you suggested. For the public ip of the host I got the same error as above and when I tried the docker ip of host system I got a connection refused error. It doesn't let me curl the docker ip from inside the jenkins container or the pipeline so I think it is an issue with how jenkins is interacting with the docker network. I am going to try to see if I can run jenkins in another way to get it to work

    – user10620554
    Jan 7 at 18:17





















  • I agree that it has to be something how jenkins is run...I tried doing what you suggested. For the public ip of the host I got the same error as above and when I tried the docker ip of host system I got a connection refused error. It doesn't let me curl the docker ip from inside the jenkins container or the pipeline so I think it is an issue with how jenkins is interacting with the docker network. I am going to try to see if I can run jenkins in another way to get it to work

    – user10620554
    Jan 7 at 18:17



















I agree that it has to be something how jenkins is run...I tried doing what you suggested. For the public ip of the host I got the same error as above and when I tried the docker ip of host system I got a connection refused error. It doesn't let me curl the docker ip from inside the jenkins container or the pipeline so I think it is an issue with how jenkins is interacting with the docker network. I am going to try to see if I can run jenkins in another way to get it to work

– user10620554
Jan 7 at 18:17







I agree that it has to be something how jenkins is run...I tried doing what you suggested. For the public ip of the host I got the same error as above and when I tried the docker ip of host system I got a connection refused error. It doesn't let me curl the docker ip from inside the jenkins container or the pipeline so I think it is an issue with how jenkins is interacting with the docker network. I am going to try to see if I can run jenkins in another way to get it to work

– user10620554
Jan 7 at 18:17






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030106%2fhow-to-get-sonarqube-running-in-docker-container-to-connect-to-localhost9000%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







UllMr8uhvojCY y
TVrkvnr,n WHdq9Hpn8eRiyuJ6pMsQMUaO,J7khpEXk,Cchsp3QU80i Y5EwvSAtIX,THBK 3Mmc2xSxG

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas