SonarQube - 以Docker方式启动SonarQube

1 - SonarQube镜像

https://hub.docker.com/_/sonarqube/

Dockerfile - 7.9.1-community
https://github.com/SonarSource/docker-sonarqube/blob/8ae0fadc72fef64334998e811f1b9cf68a458a2c/7/community/Dockerfile

2 - 准备动作

永久修改Linux系统级别的参数

[root@node201 ~]# vim /etc/sysctl.conf
[root@node201 ~]# cat /etc/sysctl.conf |grep -v "#"
vm.max_map_count = 262144
fs.file-max = 65536
[root@node201 ~]# 
[root@node201 ~]# vim /etc/security/limits.conf
[root@node201 ~]# cat /etc/security/limits.conf |grep -v "#"
*    soft    nofile    65536
*    hard    nofile    65536
[root@node201 ~]# 
[root@node201 ~]# reboot
......
......
......
[root@node201 ~]# sysctl vm.max_map_count
vm.max_map_count = 262144
[root@node201 ~]# sysctl fs.file-max
fs.file-max = 65536
[root@node201 ~]# ulimit -n
65536
[root@node201 ~]# ulimit -u
31155
[root@node201 ~]#

3 - 拉取Sonar镜像并启动

3.1 拉取镜像

命令

docker pull postgres:10
docker pull sonarqube:7.9.1-community

实例

[root@md200 ~]# docker pull postgres:10
10: Pulling from library/postgres
d599a449871e: Pull complete 
eadd55e4a4ae: Pull complete 
17eea069a47f: Pull complete 
22b703021b03: Pull complete 
5fa72174baec: Pull complete 
338e0b17322b: Pull complete 
05fd528a5e36: Pull complete 
c224328d751f: Pull complete 
f4319784a7ce: Pull complete 
6b0ef024e116: Pull complete 
5bc4176bd4c3: Pull complete 
79c29b3c031a: Pull complete 
9419079907eb: Pull complete 
4b9b9c707beb: Pull complete 
Digest: sha256:74e63f8b55e9b0ca55b78abb203d01e47c5ac7d3f10af09f91d5932943c6bb14
Status: Downloaded newer image for postgres:10
docker.io/library/postgres:10
[root@md200 ~]# 
[root@md200 ~]# 
[root@md200 ~]# docker pull sonarqube:7.9.1-community
7.9.1-community: Pulling from library/sonarqube
000eee12ec04: Pull complete 
2f1dc2bdcfe1: Pull complete 
eec880363624: Pull complete 
8992c959a11d: Pull complete 
25ff10872c55: Pull complete 
9a775036a9e6: Pull complete 
10640c614c1e: Pull complete 
0a5459c4b518: Pull complete 
b68f6850bf39: Pull complete 
Digest: sha256:64d3a0e6fc899542d9171b0a94135ea7c4b51fbb25842ca782baf0de00f66535
Status: Downloaded newer image for sonarqube:7.9.1-community
docker.io/library/sonarqube:7.9.1-community
[root@md200 ~]# 
[root@md200 ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
jenkinsci/blueocean   latest              c1fc8b2b664c        41 hours ago        563MB
postgres              10                  1ba73c5b23e7        2 weeks ago         250MB
sonarqube             7.9.1-community     ea9ce8f562b5        2 weeks ago         480MB
hello-world           latest              fce289e99eb9        11 months ago       1.84kB
[root@md200 ~]#

3.2 运行容器

启动postgres

docker run \
  -d \
  --name postgres10 \
  -p 5432:5432 \
  -e POSTGRES_USER=sonar \
  -e POSTGRES_PASSWORD=123456 \
  postgres:10

启动SonarQube

docker run \
  -d \
  --name sonarqube7.9 \
  -p 9000:9000 \
  --link postgres10 \
  -e SONARQUBE_JDBC_URL=jdbc:postgresql://postgres10:5432/sonar \
  -e SONARQUBE_JDBC_USERNAME=sonar \
  -e SONARQUBE_JDBC_PASSWORD=123456 \
  -v sonarqube_conf:/opt/sonarqube/conf \
  -v sonarqube_extensions:/opt/sonarqube/extensions \
  -v sonarqube_logs:/opt/sonarqube/logs \
  -v sonarqube_data:/opt/sonarqube/data \
  sonarqube:7.9.1-community

映射SonarQube存储(如果需要)

  -v sonarqube_conf:/opt/sonarqube/conf \
  -v sonarqube_extensions:/opt/sonarqube/extensions \
  -v sonarqube_logs:/opt/sonarqube/logs \
  -v sonarqube_data:/opt/sonarqube/data \

实例

[root@md200 ~]# docker run \
>   -d \
>   --name postgres10 \
>   -p 5432:5432 \
>   -e POSTGRES_USER=sonar \
>   -e POSTGRES_PASSWORD=123456 \
>   postgres:10
32f698f11a3a814d01d554f92f10acac3f3735e91b51ed56ff9062a3528a4755
[root@md200 ~]# 
[root@md200 ~]# docker run \
>   -d \
>   --name sonarqube7.9 \
>   -p 9000:9000 \
>   --link postgres10 \
>   -e SONARQUBE_JDBC_URL=jdbc:postgresql://postgres10:5432/sonar \
>   -e SONARQUBE_JDBC_USERNAME=sonar \
>   -e SONARQUBE_JDBC_PASSWORD=123456 \
>   -v sonarqube_conf:/opt/sonarqube/conf \
>   -v sonarqube_extensions:/opt/sonarqube/extensions \
>   -v sonarqube_logs:/opt/sonarqube/logs \
>   -v sonarqube_data:/opt/sonarqube/data \
>   sonarqube:7.9.1-community
85ade3d038eee52616e820917079f532351baba795b3cc7cbdfab72026625676
[root@md200 ~]#

4 - 检查状态

容器运行状态

[root@md200 ~]# docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                                              NAMES
85ade3d038ee        sonarqube:7.9.1-community   "./bin/run.sh"           5 seconds ago       Up 4 seconds        0.0.0.0:9000->9000/tcp                             sonarqube7.9
32f698f11a3a        postgres:10                 "docker-entrypoint.s…"   10 minutes ago      Up 10 minutes       0.0.0.0:5432->5432/tcp                             postgres10
a99b21fb6ce8        jenkinsci/blueocean         "/sbin/tini -- /usr/…"   20 minutes ago      Up 20 minutes       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   myjenkins
[root@md200 ~]# 

防火墙

[root@md200 ~]# firewall-cmd --zone=public --permanent --add-port=9000/tcp
success
[root@md200 ~]# firewall-cmd --zone=public --permanent --add-port=5432/tcp
success
[root@md200 ~]# 
[root@md200 ~]# firewall-cmd --reload
success
[root@md200 ~]# 

浏览器访问 http://192.168.16.200:9000 
初始使用 admin/admin 登录

查看数据库信息

5 - 设置中文界面

根据提示重启Sonar Server

中文界面

6 - 参考信息

posted @ 2019-12-21 00:16  Anliven  阅读(2846)  评论(0编辑  收藏  举报