Quick setup of SonarQube using Docker Compose.
sudo sysctl -w vm.max_map_count=262144
sudo sysctl -pUse this Docker Compose file: sonarqube-docker-compose.yml
sudo docker compose up -dOnce your SonarQube container is up and running, you can access the web dashboard via the following URL:
http://localhost:9000
or
http://<YOUR_SONAR_HOST>:9000
Use the default credentials on the first login:
- Username:
admin - Password:
admin
Change the default password after your first login.
You can create a new project locally or by integrating with DevOps platforms (such as GitHub, GitLab, Bitbucket, etc.).
- Navigate to the Projects tab in the SonarQube dashboard.
- Click "Create Project", then choose "Local Project".
- Enter Project display Name and unique Project Key:
- Set your project settings and click Create Project.
- Go to the Administration tab.
- Navigate to General Settings → DevOps Platform Integrations.
- Under GitLab Configuration, fill in the fields:
- Name: A label like
GitLab. - GitLab API URL: e.g.,
https://gitlab.com/api/v4orhttp://your-gitlab-server/api/v4. - Personal Access Token: Create this in GitLab (see below).
- Name: A label like
- In GitLab, click your profile avatar on the top-right → select Edit Profile.
- From the sidebar, click Access Tokens.
- Enter a name, select API scope, and click Create Token.
- Copy the token (it will only be shown once) and paste it into SonarQube’s GitLab integration form.
- Click Save and ensure the configuration is marked as Valid.
- Go back to the Projects tab.
- Click "Create Project", then choose "From DevOps Platform (e.g., GitLab)".
- Select your GitLab repository from the list.
- Set your project settings and click Create Project.
Tip: You can find the Project Key in the "Project Information" tab of the your project in the SonarQube dashboard.
You need the Project Key whenever you scan this project and send the analysis results to SonarQube.
- In the SonarQube dashboard, go to Projects and click on your project.
- Inside the project, open the Project Information.
- On this page, locate the Project Key field.
- Copy the value of Project Key and keep it – you will use this value whenever you configure a scanner to analyze this project.
To authenticate and send scan reports to SonarQube, you need to create a personal access token.
- Log into the SonarQube dashboard.
- Click on your profile avatar (top-right corner) and select "My Account".
- Go to the "Security" tab.
- Under "Generate Tokens", generate a token for a project or global.
- Copy and save the token. You will need it to authenticate the scanner.
Tokens are shown only once. Make sure to store them securely.
You can run SonarScanner either manually from your terminal or automatically in your CI/CD pipeline.
Use the official Docker image of sonar-scanner:
docker run --rm \
-v "$(pwd):/usr/src" \
sonarsource/sonar-scanner-cli \
-Dsonar.projectKey=<YOUR_PROJECT_KEY> \
-Dsonar.sources=. \
-Dsonar.host.url=http://<YOUR_SONAR_HOST>:9000 \
-Dsonar.token=<YOUR_SONAR_TOKEN> \
-Dsonar.exclusions=.git/**/* \
-Dsonar.telemetry.enabled=false \
-Dsonar.update.disable=trueOr you can make a sonar-project.properties file at the project root:
docker run --rm \
-v "$(pwd):/usr/src" \
sonarsource/sonar-scanner-cliSonarScanner will read all settings from sonar-project.properties.
Tip: Replace
<YOUR_PROJECT_KEY>,<YOUR_SONAR_HOST>and<YOUR_SONAR_TOKEN>with your real values.
Add this job to your .gitlab-ci.yml to trigger analysis on every branch push:
Tip: Add
SONAR_PROJECTKEY,SONAR_HOST_URLandSONAR_TOKENCI/CD Variable in repository of project.
-
Go to Settings → CI/CD → Variables in your GitLab project.
-
Add the following variables (exact key names):
SONAR_HOST_URL→http://<YOUR_SONAR_HOST>:9000SONAR_TOKEN→ your SonarQube access tokenSONAR_PROJECT_KEY→ the Project Key of your SonarQube project
-
Push your code; each branch will automatically be scanned and results uploaded to the SonarQube dashboard.





