DEV Community

Gopikrishna chodapaneedi
Gopikrishna chodapaneedi

Posted on

Installing SonarQube with PostgreSQL Using Docker on Ubuntu/Linux Introduction

While setting up a CI/CD pipeline with Jenkins, Docker, Kubernetes, and ArgoCD, I faced several dependency conflicts while installing SonarQube directly on the server. Different Java versions, PostgreSQL configurations, and package dependencies often caused installation failures.

To eliminate these issues, I chose to run PostgreSQL and SonarQube as separate Docker containers. This approach made the setup portable, easy to manage, and isolated from the host operating system.

In this blog, I'll walk through the complete installation process.

Prerequisites
Ubuntu 22.04 (or any Linux distribution)
Docker installed
Docker service running
Internet connection

Verify Docker installation:

docker --version

Check Docker service:

sudo systemctl status docker

If Docker is not running:

sudo systemctl start docker
sudo systemctl enable docker

Step 1: Create a Docker Network

Creating a dedicated Docker network allows SonarQube and PostgreSQL containers to communicate securely.

docker network create sonar-network

Verify:

docker network ls

Step 2: Run PostgreSQL Container

SonarQube stores all its configuration and analysis data inside a PostgreSQL database.

Create the PostgreSQL container

docker run -d \
--name postgres \
--network sonar-network \
-e POSTGRES_USER=sonar \
-e POSTGRES_PASSWORD=sonar \
-e POSTGRES_DB=sonarqube \
-v sonar-postgres-data:/var/lib/postgresql/data \
postgres:15

Verify:

docker ps

Expected output:

postgres
STATUS: Up
PORTS: 5432

Step 3: Run SonarQube Container

Now start SonarQube and connect it to the PostgreSQL container.

docker run -d \
--name sonarqube \
--network sonar-network \
-p 9000:9000 \
-e SONAR_JDBC_URL=jdbc:postgresql://postgres:5432/sonarqube \
-e SONAR_JDBC_USERNAME=sonar \
-e SONAR_JDBC_PASSWORD=sonar \
-v sonarqube_data:/opt/sonarqube/data \
-v sonarqube_logs:/opt/sonarqube/logs \
-v sonarqube_extensions:/opt/sonarqube/extensions \
sonarqube:lts-community

Step 4: Verify Containers

docker ps

Expected:

CONTAINER ID IMAGE
xxxxxxxxxxxx postgres:15
xxxxxxxxxxxx sonarqube:lts-community
Step 5: Access SonarQube

Open your browser:

http://:9000

Example:

http://13.xxx.xxx.xxx:9000

Default credentials:

Username : admin
Password : admin

SonarQube will ask you to change the default password after the first login

Top comments (2)

Collapse
 
swapnoneel123 profile image
Swapnoneel Saha

the separate network and named volumes are a good start. before using this outside a local test, replace the example database password, keep port 9000 behind a reverse proxy or private network, and add health checks that wait for postgres before sonarqube starts. document backup and restore for both database and volumes, then pin image versions instead of using a moving tag. these steps will make the setup safer to repeat.

Collapse
 
gopikrishna_chodapaneedi profile image
Gopikrishna chodapaneedi

Thanks for sharing the valuable information.