Here’s a README.md you can drop into the root of your SonarQube setup directory to document the entire process.
# SonarQube on Ubuntu with Docker Compose
This guide walks through installing and testing **SonarQube (Community Edition)** on Ubuntu using Docker Compose and running a sample scan.
---
## Prerequisites
- Ubuntu 20.04+ with Docker and Docker Compose installed
```bash
sudo apt update
sudo apt install docker.io docker-compose-plugin -y
sudo systemctl enable --now docker- At least 2 GB of RAM
Create a folder to hold the Compose file and volumes:
mkdir ~/sonarqube
cd ~/sonarqubeversion: "3.8"
services:
postgres:
image: postgres:15
container_name: sonarqube-db
restart: unless-stopped
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
POSTGRES_DB: sonar
volumes:
- postgres_data:/var/lib/postgresql/data
sonarqube:
image: sonarqube:latest
container_name: sonarqube
restart: unless-stopped
depends_on:
- postgres
environment:
SONAR_JDBC_URL: jdbc:postgresql://postgres:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
ports:
- "9000:9000"
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
volumes:
postgres_data:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:docker compose up -dCheck containers:
docker compose psView logs until you see SonarQube is operational:
docker logs -f sonarqubeOpen a browser:
http://<server-ip>:9000
Login with:
- Username:
admin - Password:
admin(you’ll be asked to change it)
Generate a token for scans:
- Go to My Account → Security → Generate Tokens
- Copy the token (40-character string)
curl http://localhost:9000/api/system/healthShould return:
{"health":"GREEN"}Install Java (required by Sonar Scanner):
sudo apt install openjdk-17-jre -yDownload and add Sonar Scanner to PATH:
sudo apt install unzip
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006.zip
unzip sonar-scanner-cli-5.0.1.3006.zip
export PATH=$PATH:$PWD/sonar-scanner-cli-5.0.1.3006.zip/binCreate a sample project:
mkdir sample-project && cd sample-project
echo "print('Hello SonarQube')" > hello.pyRun the scanner (replace <TOKEN> with your actual token, no angle brackets):
sonar-scanner \
-Dsonar.projectKey=sample \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=squ_f95660038a9a946a924f864171e54b5b43830508When the scan completes, refresh the SonarQube UI to see the analysis.
-
Stop:
docker compose down -
Update images:
docker compose pull docker compose up -d
- Adjust memory if needed; SonarQube typically needs at least 2 GB RAM.
- Use
sonarqube:<version>-communityif you need a fixed version.
Save this as `README.md` in your `~/sonarqube` directory:
```bash
nano ~/sonarqube/README.md
# (paste content, save, exit)
You now have a complete reference for setup, testing, and maintenance.