This repository provides an evergreen, persistent Docker Compose setup to run the SonarQube Community Edition with a dedicated PostgreSQL database.
This configuration is designed for developers who want a reliable, local SonarQube instance. It is "evergreen," meaning it uses floating tags (like community and latest) to pull the newest compatible images on first setup.
💡 Need Multi-Branch Analysis?
If you need to analyze multiple branches and pull requests, check out the SonarQube with Branch Plugin version of this setup, which includes the Community Branch Plugin for free multi-branch support.
- Stable Database: Uses a dedicated PostgreSQL database, as recommended by SonarSource for persistent data storage.
- Persistent Storage: All data (database, SonarQube data, extensions, logs) is stored in named Docker volumes, so your data survives container restarts and image updates.
- Isolated Networking: Both services run on a custom bridge network, allowing them to communicate securely by name.
-
Download: Clone this repository or download the
docker-compose.ymlfile into a new directory (for example,~/docker/sonarqube). -
Start the Services: From inside that directory, run:
docker-compose up -d
This will pull the latest images (if you don't have them) and start the containers.
-
Access SonarQube: Wait 1-2 minutes for the server to initialize. You can check the logs with
docker-compose logs -f sonarqube.Once it's running, access the dashboard in your browser at: http://localhost:9000
-
Login:
- Default Username:
admin - Default Password:
admin(You will be prompted to change the password on first login).
- Default Username:
This docker-compose.yml is designed to be a flexible template. Here is how you can customize it.
-
image: postgres:latestThis file usespostgres:latestto always get the newest stable PostgreSQL version. If you prefer to lock into a specific major version, you can change this.- Example:
image: postgres:16orimage: postgres:15
- Example:
-
environment:You can change thePOSTGRES_USER,POSTGRES_PASSWORD, orPOSTGRES_DBvalues. If you change these, you must update theSONAR_JDBC_...variables in thesonarqubeservice to match. -
ports: - "5433:5432"This line is optional. It exposes the database to your host PC on port5433. This is only useful if you want to connect to the database with an external tool (like DBeaver or pgAdmin). SonarQube does not need this to function, so you can safely remove it for better security.
-
image: sonarqube:communityThis is the most important setting. The tag determines your SonarQube version.sonarqube:community(Recommended Default): This tag points to the latest Community Edition. It is updated frequently and avoids the "version is no longer active" error.sonarqube:lts-community: Use this tag if you specifically want the Long-Term Support (LTS) version, which is more stable and updated less frequently.sonarqube:X.X.X-community: You can "pin" a specific version (for example,sonarqube:25.10.0.114319-community) if you need to guarantee a specific release.
-
ports: - "9000:9000"If you already have a service on your host using port9000, you can change the host port (the left side).- Example:
ports: - "9001:9000"will make SonarQube available athttp://localhost:9001.
- Example:
Because this setup uses floating tags, you can update your SonarQube and PostgreSQL images by running:
# 1. Pull the newest images defined in your compose file
docker-compose pull
# 2. Re-create the containers with the new images
docker-compose up -dThe new containers will start and connect to your existing data volumes.
This error can happen if you docker-compose pull after a long time. SonarQube cannot always jump from a very old version (like 9.x) directly to a very new one (like 11.x) while migrating the database.
Fix (This will delete all your SonarQube analysis data):
- Stop and remove all containers AND volumes.
docker-compose down -v
- Start fresh. This will create a new, empty database for the new version.
docker-compose up -d
If you need to analyze multiple branches and pull requests (features typically only available in commercial editions), check out this enhanced version:
docker-compose-sonarqube-branch-plugin-with-postgres
This setup includes the SonarQube Community Branch Plugin, which adds:
- ✅ Multi-branch analysis
- ✅ Pull request decoration
- ✅ Branch comparison
- ✅ CI/CD integration for branches
Perfect for teams working with feature branches and pull request workflows!
- SonarQube Downloads: sonarsource.com/products/sonarqube/downloads/
- (Good for seeing what the current LTS and Latest versions are)
- SonarQube on Docker Hub: hub.docker.com/_/sonarqube
- SonarQube Tags: hub.docker.com/_/sonarqube/tags (See all available versions)
- PostgreSQL on Docker Hub: hub.docker.com/_/postgres
- PostgreSQL Tags: hub.docker.com/_/postgres/tags
- SonarQube Installation Docs (Docker):
- Docker Compose File Reference: docs.docker.com/compose/compose-file/
This project is licensed under the MIT License.