Trouble integrating SonarQube into CI pipeline

I have a pipeline that i would like to integrate SonarQube into so it can analyze my master branch. I created 2 containers on Docker, one with SonarQube running on it and one with a GitLab runner. After following the SonarQube instructions on their website (Link at the bottom of this post) i ran into some trouble. This is my job log:

The first error message says:

> ERROR: SonarQube server [[http://localhost:9000]](http://localhost:9000]/) can not be reached

Which is weird because when i open http://localhost:9000 in my browser it opens SonarQube.

This is my .gitlab-ci.yml which is the same as in the SonarQube Docs:

Has anyone ran into this problem before? Is it a SonarQube problem or maybe a Docker problem?

I think the problem is that my runner is trying to connect to the SonarQube container but it can’t make the connection.

I have spent multiple hours trying to find a solution and reading thru the documentation but none of them work for me, including: creating new runners, trying to expose ports in docker and making a network bridge between the 2 containers. Has anyone ran into this problem before?

Hi @stefanDB
This mostly depends on how have you setup your SonarQube container. I assume you have exposed port 9000 for SonarQube container and that’s why it is listening on your PC’s localhost:9000. I also assume you are using GitLab Runner Docker executor so the GitLab Runner is actually running as a service and not in Docker. Jobs are executed in containers.

You cannot use http://localhost:9000 as SonarQube address, because in each container network is isolated and each container has it’s own localhost. Your SonarQube is not running in the same container as your Pipeline Job, that’s why it won’t connect. You need to use an actual IP address of your PC so Docker can route the traffic outside the Job container to your PC’s network.

You’re a hero! I changed my host url inside SonarQube to my own ip-adress and now it works! Thank you!