https://docs.sonarqube.org/latest/setup/install-server/
docker compose:
version: "3"
services:
sonarqube:
image: sonarqube:8-community
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
- sonarqube_temp:/opt/sonarqube/temp
ports:
- "9000:9000"
db:
image: postgres:12
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
volumes:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
sonarqube_temp:
postgresql:
postgresql_data:
Client:
# 1. Create a separate network
docker network create sonarqube-tier
# 2. Create a volume for the postgres container
docker volume create --name postgresql_data
# 3. Start the postgres container
docker run -d --name postgresql -e ALLOW_EMPTY_PASSWORD=yes -e POSTGRESQL_USERNAME=bn_sonarqube -e POSTGRESQL_DATABASE=avasdream_sonarqube -e POSTGRESQL_PASSWORD=avasdream1234 --net sonarqube-tier --volume postgresql_data:/bitnami/postgresql bitnami/postgresql:latest
# 4. Start the Sonarqube server
docker run -d --name sonarqube -p 80:9000 -e ALLOW_EMPTY_PASSWORD=yes -e SONARQUBE_DATABASE_USER=bn_sonarqube -e SONARQUBE_DATABASE_NAME=avasdream_sonarqube -e SONARQUBE_DATABASE_PASSWORD=avasdream1234 --net sonarqube-tier --volume sonarqube_data:/bitnami bitnami/sonarqube:latest
# 5. Log in to sonarqube at http://127.0.0.1 with admin/bitnami and create a project
# 6. Start the Sonarqube scanner
docker run --rm -v $path_to_repo:/usr/src sonarsource/sonar-scanner-cli -Dsonar.projectKey=$project_name -Dsonar.sources=. -Dsonar.host.url=http://$ip_of_docker_host_machine -Dsonar.login=cf71c2400e17e20e2e3e102ea78f0f9448d27463
Java and Maven
docker run -it --rm --name my-maven-project -v $path:/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean install
docker run -it --rm --name my-maven-project -v $path:/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn sonar:sonar -Dsonar.projectKey=$project-name -Dsonar.host.url=http://192.168.0.45 -Dsonar.login=d9987b01a0be06671a18335308e99a5b9e42d54a
Error 137 -> Lack of memory