How to Install and Set Up SonarQube with Docker

thowfick official
2 min readFeb 7, 2025
A conceptual illustration of SonarQube and Docker working together , thowfickofficial

SonarQube is an open-source platform for continuous code quality inspection. It helps developers detect bugs, vulnerabilities, and code smells in various programming languages. In this guide, we will walk through the step-by-step process of installing and running SonarQube using Docker.

Prerequisites

Before proceeding, ensure that you have the following installed on your system:

  • Docker (Install from here)
  • Docker Compose (Optional, but recommended for easier management)
  • At least 2GB of RAM for smooth operation

Method 1: Install SonarQube Using Docker

Step 1: Pull SonarQube Docker Image

The first step is to download the latest SonarQube image from Docker Hub. Run the following command:

docker pull sonarqube

Step 2: Set Up PostgreSQL Database for SonarQube

SonarQube requires a database to store its analysis data. We will use PostgreSQL as our database. Run the following command to start a PostgreSQL container:

docker run -d \
--name sonarqube-db \
-e POSTGRES_USER=sonar \
-e POSTGRES_PASSWORD=sonar \
-e POSTGRES_DB=sonarqube \
postgres:alpine

Step 3: Run SonarQube Container

Once the database container is running, start the SonarQube container and link it to the PostgreSQL database:

docker run -d \
--name sonarqube \
-p 9000:9000 \
--link sonarqube-db:db \
-e SONAR_JDBC_URL=jdbc:postgresql://db:5432/sonarqube \
-e SONAR_JDBC_USERNAME=sonar \
-e SONAR_JDBC_PASSWORD=sonar \
sonarqube

Step 4: Access SonarQube Dashboard

Once SonarQube is running, open your web browser and navigate to:

http://localhost:9000

The default login credentials are:

  • Username: admin
  • Password: admin

Step 5: Set Up Sonar Scanner

To analyze your projects, you need to install Sonar Scanner and configure it in your system.

Configure Sonar Scanner Environment Variables

  1. Open the ~/.bashrc file in a text editor:
nano ~/.bashrc

2. Add the following lines at the end of the file:

export SONAR_SCANNER_HOME=/path/to/sonar-scanner
export PATH=$SONAR_SCANNER_HOME/bin:$PATH

3. Save the file and apply the changes:

source ~/.bashrc

Method 2: Alternative Installation Steps

Step 1: Pull SonarQube Docker Image

docker pull sonarqube

Step 2: Set Up PostgreSQL Database

docker run -d --name sonarqube-db -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -e POSTGRES_DB=sonarqube postgres:alpine

Step 3: Run SonarQube Container

docker run -d --name sonarqube -p 9000:9000 --link sonarqube-db:db -e SONAR_JDBC_URL=jdbc:postgresql://db:5432/sonarqube -e SONAR_JDBC_USERNAME=sonar -e SONAR_JDBC_PASSWORD=sonar sonarqube

This command sets up the SonarQube container with a link to the PostgreSQL database.

Step 4: Set Up Sonar Scanner

nano ~/.bashrc
export SONAR_SCANNER_HOME=/path/to/sonar-scanner# Add Sonar Scanner to PATH
export PATH=$SONAR_SCANNER_HOME/bin:$PATH

Conclusion

You have successfully installed and configured SonarQube using Docker and PostgreSQL. Now, you can start analyzing your code quality and improve your projects. Happy coding!

Need More Help?

Check out the official SonarQube documentation for advanced configurations and best practices.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response

Recommended from Medium

Lists

See more recommendations