镜像拉取 9.9.6
docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/sonarqube:9.9.6-community
引用改名
docker tag swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/sonarqube:9.9.6-community sonarqube
windows docker部署(注意文件夹映射路径)
docker run -d --name sonarqube -p 11000:9000 -v D:\\data\\sonar\\data:/opt/sonarqube/data -v D:\\data\\sonar\\logs:/opt/sonarqube/logs -v D:\\data\\sonar\\extensions:/opt/sonarqube/extensions -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true sonarqube
==========================
镜像拉取10
docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/bitnami/sonarqube:10
装postgres(账号密码db都没创建成功,懒得删了)
docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=admin -e POSTGRES_USER=admin -e POSTGRES_DB=sonar -v D:\data\postgresql:/var/lib/postgresql/data -d postgres
进容器
docker exec -it postgres psql -U postgres
创建db
CREATE DATABASE sonar;
创建账号密码
CREATE USER admin WITH PASSWORD 'admin';
运行容器(自行修改配置)
docker run -d --name sonarqube10 -p 9000:9000 -p 9092:9092 -v D:/data/sonar10/conf:/opt/sonarqube/conf -v D:/data/sonar10/data:/opt/sonarqube/data -v D:/data/sonar10/logs:/opt/sonarqube/logs -e SONARQUBE_DATABASE_HOST=localhost -e SONARQUBE_DATABASE_PORT=5432 -e SONARQUBE_DATABASE_NAME=sonar -e SONARQUBE_DATABASE_USER=admin -e SONARQUBE_DATABASE_PASSWORD=admin sonarqube10
如果admin admin进不去,则进到db 重置密码
update users set crypted_password='100000$t2h8AtNs1AlCHuLobDjHQTn9XppwTIx88UjqUm4s8RsfTuXQHSd/fpFexAnewwPsO6jGFQUv/24DnO55hY6Xew==', salt='k9x9eN127/3e/hf38iNiKwVfaVk=', hash_method='PBKDF2', reset_password='true', user_local='true' where login='admin';
java代码pom下加入
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>http://192.168.0.198:9000</sonar.host.url>
<sonar.login>sqa_d33536bba3b7d11be992db2a915ab5ab9aed73aa</sonar.login>
</properties>
</profile>
</profiles>
mvn执行
mvn clean verify sonar:sonar
由于账号问题提示token或者password问题,建议直接新建user用户并且授予权限
地址:docker.io/sonarqube:9.9.6-community - 镜像下载 | docker.io (aityp.com)