Docker sonarsource/sonar-scanner-cli returns SonarQube server [http://10.99.198.149:31680] can not be reached

SonarQube version: 7.9.1.27448
SonarScanner version: 4.6.0.2311

I set up my SonarQube in a local kubernetes cluster using Docker Desktop for Windows. I followed the tutorial here and set up pod and service for sonarqube and postgres as well as persistent volume and the claim. The sonarqube service is exposed to 10.99.198.149 (and localhost as well…).

describe-sonarqube-service

The source code is in the WSL folder.

When I ran the sonarsource/sonar-scanner-cli docker image with the following options:

docker run -e SONAR_HOST_URL='http://localhost:31680' -e SONAR_LOGIN='3542cea554928abd60a801209a7e1eb8adc15276' -v '/home/ubuntu/workspace/2021-04-23--coderise-k8s-sonarqube/src' sonarsource/sonar-scanner-cli

However, it returned to me SonarQube server [http://localhost:31680] can not be reached. I also switched the URL to 10.99.198.149 but it still gives me the same thing.

What should I have done instead? I read that it’s possible that the docker image cannot access the local kubernetes cluster. How do I make it connect?

Thanks

Hi @zacktzeng ,

careful when working with localhost and containers. passing SONAR_HOST_URL='http://localhost:31680' to a container will result in localhost to the started container and not to localhost on your system.
when working with docker desktop and k8s you need to expose the service to your public NIC or work with tunneled connections, as in make the network of your node accessible from the scanner container.

in the linked tutorial they are working with minikube, which has a slightly different functionality than docker desktop. i would recommend you try it again with minikube if you want to have it local only.

If the container isn’t part of the kubernetes cluster, will it work if I expose the sonarqube service with a NodePort service? My guess is that I will need the worker node’s ID, but if I i am in a local k8s cluster, the node IP would be localhost. Is there another IP I could have used? Is 127.0.0.1 better?

localhost and 127.0.0.1 will result to the loopback device inside the container, so both will not work. you need to make sonarqube accessible on another NIC.

tbh i think a local k8s cluster without a real ingress or load balancer is resulting in not needed complexity. maybe it would make sense if you want to stick to a local development to use compose?