Setup SonarCube server with docker-compose and connect to GitHub/Azure DevOps
Table of Contents
Add Title
SonarQube is a popular open-source platform for static code analysis, which helps developers identify and prevent bugs, vulnerabilities, and code smells in their code. With Docker Compose, you can easily set up a SonarQube instance and run it in a containerized environment.
To get started, you will need to have Docker and Docker Compose installed on your system. Once you have those installed, you can create a docker-compose.yml file to define the services for your SonarQube installation. Here is an example docker-compose.yml file that you can use:
version: '3.7'
services:
sonarqube:
image: sonarqube:8.6.0
ports:
- 9000:9000
- 9092:9092
environment:
- SONARQUBE_JDBC_USERNAME=sonar
- SONARQUBE_JDBC_PASSWORD=sonar
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
db:
image: postgres:12.3
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
This docker-compose.yml file defines two services: sonarqube and db. The sonarqube service uses the official SonarQube Docker image and exposes ports 9000 and 9092 for accessing the SonarQube web interface and analysis reports. The db service uses the official PostgreSQL Docker image and provides the database for SonarQube.
To start the SonarQube service, run the following command in the same directory as your docker-compose.yml file:
$ docker-compose up -d
This command will start the sonarqube and db services in the background. Once the services are up and running, you can access the SonarQube web interface by visiting http://localhost:9000 in your web browser.
To stop the SonarQube services, run the following command:
$ docker-compose down
That’s it! You should now have a working SonarQube instance running in a Docker container. With this setup, you can easily run static code analysis on your projects and ensure that your code is of high quality.