logo
  • React
  • Sonarqube

Setup and Run Sonarqube in Local Environment

August 05, 2024


How to setup and run Sonarqube in local environment

Setup Docker Image

$ docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest

after run above command, docker will be automatically download required docker image which is sonarqube:latest

Run SonarQube and Create New Project

after setup the docker image, log in to http://localhost:9000 using administrator credentials:

  • login: admin
  • password: admin

after login you must create a new password for local sonarqube, and then create a new project

  • Set up Project Key and Display name
  • Under provide a token, select generate a token. and select Generate and click Continue.
  • After generate token now you can run analysis on your project

Run SonarScanner on Docker

You can use this following command to start scan your project:

docker run \
    --rm \
    -v "${YOUR_REPO/PATH_TO_PROJECT}:/usr/src" \
    --network="host" \
    -e SONAR_HOST_URL="${SONARQUBE_URL}" \
    -e SONAR_SCANNER_OPTS="-Dsonar.projectKey=${YOUR_PROJECT_KEY}" \
    -e SONAR_TOKEN="${YOUR_TOKEN}" \
    sonarsource/sonar-scanner-cli

Conclusion

In this example, I show how easily SonarQube platform could be run from any local machine that has Docker installed.