Build sonarqube code quality detection platform based on docker composition

Time:2021-5-8

1、 Demand

In the process of our development, it is inevitable that sometimes the code is not standardized, or there are some static bug problems. At this time, a good code checking tool is very necessary, andsonarqubeIt just meets the whole requirement.

2、 The compilation of docker compose file

version: "3"

services:
  sonarqube:
    image: sonarqube:8.3.1-community
    container_name: sonarqube
    restart: 'no'
    networks:
      - sonarnet
    environment:
      - sonar.jdbc.username=sonar
      - sonar.jdbc.password=sonar
      - sonar.jdbc.url=jdbc:postgresql://sonarqube-postgre:5432/sonarqube
    ports:
      - "9010:9000"
      - "9011:9092"
    depends_on:
      - sonarqube-postgre
    links:
      - sonarqube-postgre
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins

  sonarqube-postgre:
    image: postgres:12.3
    container_name: sonarqube-postgre
    restart: 'no'
    networks:
        - sonarnet
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
      - POSTGRES_DB=sonarqube
    volumes:
      - sonarqube_postgre_db:/var/lib/postgresql
      - sonarqube_postgre_data:/var/lib/postgresql/data

volumes:
  sonarqube_bundled-plugins:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_postgre_db:
  sonarqube_postgre_data:

networks:
  sonarnet:
    driver: bridge

3、 Operation

Docker compose - f file path up

4、 Precautions

  1. sonarqubeThe best way to mount image data is to use data volumevolume
  2. In multiplesonarqubeThe same data volume cannot be used in an instance.
  3. eachsonarqubeExamples are the bestyesownaloneOfDatabase schema

5、 Reference link

Sonarqube image https://hub.docker.com/_/ sona…
Sonarqube website https://docs.sonarqube.org/la…