SonarQube with Postgres on docker-compose
[updated 2022-08-08]
Struggling to get a working environment with SonarQube and PostgreSQL?
Use the following docker-compose file and be up and running in minutes.
It is as ‘bare’ as possible:
- use of official Docker images for both PostgreSQL and SonarQube
- no other configuration required
- use of volumes so you can backup your data
Recommended system specs
- >= 3GB of RAM
# file: docker-compose.yml
version: "3"
services:
sonarqube:
image: sonarqube:9-community
# platform: linux/amd64 # uncomment this when using Mac M1
restart: unless-stopped
environment:
- SONARQUBE_JDBC_USERNAME=sonar
- SONARQUBE_JDBC_PASSWORD=v07IGCFCF83Z95NX
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
ports:
- "9000:9000"
- "9092:9092"
volumes:
- sonarqube_conf:/opt/sonarqube/conf
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins
db:
image: postgres:14.4
# platform: linux/amd64 # uncomment this when using Mac M1
restart: unless-stopped
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=v07IGCFCF83Z95NX
- POSTGRES_DB=sonarqube
volumes:
- sonarqube_db:/var/lib/postgresql
# This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
- postgresql_data:/var/lib/postgresql/data
volumes:
postgresql_data:
sonarqube_bundled-plugins:
sonarqube_conf:
sonarqube_data:
sonarqube_db:
sonarqube_extensions:
Start this stack with the following command:
# start the containers
docker-compose up -d
You can reach your SonarQube instance at http://localhost:9000
Use the default credentials admin/admin to login.
Useful links:
- SonarQube on Docker Hub: https://hub.docker.com/_/sonarqube/
- PostgreSQL on Docker Hub: https://hub.docker.com/_/postgres/