admin/ May 16, 2018/ Docker, Linux/ 0 comments

SonarQube is an Open Source tool to measure and analysis the quality of the source code. The SonarQube tool and its plugins are written in Java, it support more than 20 programming language to code quality analysis. We can use the SonarQube in jenkins to Continous Integration.

Install Docker on Ubuntu

$  sudo apt install apt-transport-https ca-certificates curl software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt update && apt install docker-ce

Install Docker on CentOs7

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
$  sudo yum install -y docker-ce

Install Docker-compose

$ sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

Note-: In case docker-compose compose still not working use the below command.

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Create a docker-compose.yml for SonarQube

version: '3.3'

services:

  db:
    image: postgres
    restart: always
    volumes:
      - $PWD/db:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: sonar
      POSTGRES_USER: sonar

  sonarqube:
    image: sonarqube
    restart: always
    ports:
      - 9000:9000
      - 9092:9092
    volumes:
      - $PWD/sonar:/opt/sonarqube/data
    depends_on:
       - db
    environment:
      SONARQUBE_JDBC_USERNAME: sonar
      SONARQUBE_JDBC_PASSWORD: sonar
      SONARQUBE_JDBC_URL: jdbc:postgresql://db/sonar
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

Use the below Command to start and deploy the docker-compose file.

$sudo docker-compose up -d

It will pull the sonarqube, postgres and adminer images from hub.docker.com. It will create container on the machine. The SonarQube data and postgres data will be mounted on your machine.

Now Visit to http://localhost:9000 or http://hostip:9000

The default SonarQube Username Password is admin/admin

Share this Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.