1、安装docker及docker-compose
docker这里就不介绍了
在安装docker结束后安装docker-compose:
安装docker-compose:
# 建议用迅雷下载二进制文件
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 下载的文件会输出到 /usr/local/bin/docker-compose
PS:国内镜像:
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
之后给compose配置可执行权限
sudo chmod +x /usr/local/bin/docker-compose
输入docker-compose version
2、安装snoarqube
snoarqube依赖postgres数据库
所以先下载
docker pull postgres:latest
docker pull sonarqube:8.9.2-community
拉取对应镜像后,此时用到之前的docker-compose安装sonarqube :
选择一个安装路径,下面放入docker-compose.yml文件
docker-compose文件对文件内容格式要求很高,里面不能出现table的空格,如果在运行时提示异常需要调整里面的格式,db也是在services下的,如果格式异常,就会执行不了,可以进去:set number定位行数调整
- version: '3.3'
- services:
- postgres:
- image: postgres:latest
- restart: always
- container_name: postgres
- ports:
- - 5432:5432
- volumes:
- - /opt/sonarqube/postgres/postgresql:/var/lib/postgresql
- - /opt/sonarqube/postgres/data:/var/lib/postgresql/data
- environment:
- TZ: Asia/Shanghai
- POSTGRES_USER: sonar
- POSTGRES_PASSWORD: sonar
- POSTGRES_DB: sonar
-
- sonar:
- image: sonarqube:8.9.2-community
- container_name: sonar
- depends_on:
- - db
- volumes:
- - /opt/sonarqube/sonarqube/extensions:/opt/sonarqube/extensions
- - /opt/sonarqube/sonarqube/logs:/opt/sonarqube/logs
- - /opt/sonarqube/sonarqube/data:/opt/sonarqube/data
- - /opt/sonarqube/sonarqube/conf:/opt/sonarqube/conf
- ports:
- - 9000:9000
- environment:
- SONARQUBE_JDBC_URL: jdbc:postgresql://postgres:5432/sonar
- SONARQUBE_JDBC_USERNAME: sonar
- SONARQUBE_JDBC_PASSWORD: sonar
-
- db:
- image: postgres:latest
- networks:
- - sonarnet
- environment:
- POSTGRES_USER: sonar
- POSTGRES_PASSWORD: sonar
- volumes:
- - /opt/sonarqube/postgres/postgresql:/var/lib/postgresql
- - /opt/sonarqube/postgres/postgresql/data:/var/lib/postgresql/data
-
- networks:
- sonarnet:
- driver: bridge
问题,类似这种
yaml.scanner.ScannerError: while scanning for the next token
found character '\t' that cannot start any token
in "./docker-compose.yml", line 27, column 1:
'db' does not match any of the regexes
还有上面的版本号,如果提示异常需要修改。
此处提前规避安装sonarqube的问题,设置它的内存参数:
sysctl -w vm.max_map_count=262144
一切调整OK后:
执行:
docker-compose up -d
需要查看日志的话
docker-compose logs -f
一切ok
查看下docker的进程,docker ps看是否正常启动:
登录对应环境的9000端口即可登录snoarqube, 默认用户名密码都是admin,提示修改密码即可:
安装中文插件:
之后界面会提示restart server,点击即可,至此可以正常使用