To setup SonarQube on local machine we need docker running in our system (as this guide is only for docker).
Open Portainer and create a new stack and provide the following docker compose information –
version: "3"
services:
sonarqube:
image: sonarqube:lts-community
depends_on:
- sonar_db
environment:
SONAR_JDBC_URL: jdbc:postgresql://sonar_db:5432/${PG_DATABASE}
SONAR_JDBC_USERNAME: ${PG_USER}
SONAR_JDBC_PASSWORD: ${PG_PASSWORD}
ports:
- ${PUBLIC_SQ_PORT}:9000
volumes:
- sonarqube_conf:/opt/sonarqube/conf
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
- sonarqube_temp:/opt/sonarqube/temp
sonar_db:
image: postgres:13
environment:
POSTGRES_USER: ${PG_USER}
POSTGRES_PASSWORD: ${PG_PASSWORD}
POSTGRES_DB: ${PG_DATABASE}
volumes:
- sonar_db:/var/lib/postgresql
- sonar_db_data:/var/lib/postgresql/data
volumes:
sonarqube_conf:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
sonarqube_temp:
sonar_db:
sonar_db_data:
And for environment variable we have to provide the following values –
PG_USER=<YOUER_DB_USER>
PG_PASSWORD=<YOUER_DB_PASSWORD>
PG_DATABASE=<YOUER_DB_NAME>
PUBLIC_SQ_PORT=<YOUER_PUBLIC_SONARQUBE_OPEN_PORT_TO_ACCESS>
Example of the environment values –
PG_USER=sonaruser
PG_PASSWORD=mysonarc0mplxp@$$w0rd
PG_DATABASE=sonardb
PUBLIC_SQ_PORT=9001
Now deploy the stack and if everything works then you will get the running sonarqube application on your local docker environment.
Note : For first time the default user credential of sonarqube application is admin/admin . After login you have to change the credential details.