Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Adamsimsy/96cca392b9e406dd5258b0613e71c4fc to your computer and use it in GitHub Desktop.
Save Adamsimsy/96cca392b9e406dd5258b0613e71c4fc to your computer and use it in GitHub Desktop.
.NET SonarQube with Docker persistent volumes on Windows
# Run as steps, not full script
#using docker image from https://hub.docker.com/_/sonarqube/
# Step 1 - Create docker volumes
docker volume create --name sonar-conf
docker volume create --name sonar-logs
docker volume create --name sonar-data
docker volume create --name sonar-extensions
# Step 2 - Start initial container
docker run -d --name sonarqube -p 9000:9000 sonarqube
#After docker starts, copy folders to volumes
docker cp -a CONTAINER_ID:/opt/sonarqube/conf sonar-conf
docker cp -a CONTAINER_ID:/opt/sonarqube/logs sonar-logs
docker cp -a CONTAINER_ID:/opt/sonarqube/data sonar-data
docker cp -a CONTAINER_ID:/opt/sonarqube/extensions sonar-extensions
#Step 3 - Stop and remove current container
docker stop sonarqube
docker rm sonarqube
#Step 4 - Start container using volumes. You can delete the container and restore again using same command. No data lost!
docker run -d --name sonarqube -p 9000:9000 -v sonar-conf:/opt/sonarqube/conf -v sonar-data:/opt/sonarqube/data -v sonar-logs:/opt/sonarqube/logs -v sonar-extensions
:/opt/sonarqube/extensions sonarqube
#Optional - Diagnose issues
docker container logs CONTAINER_ID
#download from https://sonarcloud.io/documentation/analysis/scan/sonarscanner-for-msbuild/
#Step 5 - Now run analysis
.\SonarScanner.MSBuild.exe begin /k:"App"
& 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' "C:\Projects\App.sln" /t:Rebuild
.\SonarScanner.MSBuild.exe end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment