Docker 搭建 SonarQube

Docker 搭建 SonarQube

步骤

创建项目目录

mkdir -p /usr/local/sonarqube && cd /usr/local/sonarqube

创建所有的映射文件

mkdir -p /usr/local/sonarqube/postgres && \
mkdir -p /usr/local/sonarqube/data && \
mkdir -p /usr/local/sonarqube/extensions && \
mkdir -p /usr/local/sonarqube/logs && \
mkdir -p /usr/local/sonarqube/conf

简单的把所有目录设置为 777 权限,避免权限问题

chmod 777 /usr/local/sonarqube/postgres && \
chmod 777 /usr/local/sonarqube/data && \
chmod 777 /usr/local/sonarqube/extensions && \
chmod 777 /usr/local/sonarqube/logs && \
chmod 777 /usr/local/sonarqube/conf

创建 /usr/local/sonarqube/docker-compose.yml 文件,描述了 docker 详情:

version: '2'

services:
postgres:
image: postgres:12
container_name: sonarqube_postgres
privileged: true
ports:
- "5432:5432"
networks:
- sonarnet
restart: always
volumes:
- ./postgres:/var/lib/postgresql/data
environment:
POSTGRES_DB: sonar
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar sonarqube:
image: sonarqube:7.9-community
container_name: sonarqube
privileged: true
ports:
- "9000:9000"
restart: always
networks:
- sonarnet
depends_on:
- postgres
volumes:
- ./data:/opt/sonarqube/data
- ./extensions:/opt/sonarqube/extensions
- ./logs:/opt/sonarqube/logs
- ./conf:/opt/sonarqube/conf
environment:
SONARQUBE_JDBC_USERNAME: sonar
SONARQUBE_JDBC_PASSWORD: sonar
SONARQUBE_JDBC_URL: jdbc:postgresql://postgres:5432/sonar?useUnicode=true&characterEncoding=utf8
ulimits:
nproc: 65535
nofile:
soft: 65536
hard: 65536 networks:
sonarnet:
driver: bridge

修改一个系统配置,我启动 docker 时报有相关错误(相关报错在 /usr/local/sonarqube/logs/es.log 中)

sysctl -w vm.max_map_count=262144

启动容器

docker-compose up -d

稍等片刻,访问 SonarQube

http://ip:9000/

启动成功

Docker 搭建 SonarQube-LMLPHP

管理员账户admin/admin

05-28 18:27