How to build sonarqube using docker

How to build sonarqube using docker

Sonarqube is a code quality checking tool. Using sonar to scan the code we have written can help check the bugs, standardization and robustness of the code, which helps to improve the quality of our code.

1. Install Docker

After the installation is complete, enter the command line

docker -v

When the version number appears, the installation is complete.

. . . . . . . .

2. Install sonar image

1. Enter in the command line

docker -search sonar

You will see many sonar versions:

2. We use the command directly, docker pull sonar downloads the latest version of sonarqube by default

docker pull sonar

After the download is complete, execute docker images to view the downloaded image files. Already have sonarqube.

3. Run sonar

Command line input

docker run -p9000:9000 sonarqube

The default port of sonar is 9000. Map the port 9000 in the docker image to the host port 9000. At this time, we open the browser and enter the URL localhost:9000 to enter the docker page. The default login account and password are both admin. At this point, our sonar installation and operation is complete.

4. Persistent Sonar

If you need to persist our sonar scan data, you can use the following command to start sonar. The jdbc information is the mysql connection, username and password. Sonar will persist the scan information to MySQL.

docker run --restart=always -d --name sonarqube \
 	-p 9000:9000 \
 	-e sonar.jdbc.username=root \
 	-e sonar.jdbc.password=123456 \
 	-e sonar.jdbc.url=
jdbc:mysql://172.30.50.215:3306/payment?useUnicode=true&characterEncoding=UTF-8
\sonarqube

3. Use sonar to scan code

After logging in to the sonar page, click to create a project

Click manually. You can also select GitHub here. Using git to associate sonar with your project makes it easier to scan code branches.

Then enter a project name at random. It is recommended to make it the same as the project name.

Enter anything (it is recommended to be the same as the project name) to generate a token. After generation, click continue.

Choose maven or gradle, or others according to our project location. Sonar will automatically give the command to scan the code below. Then open our idea and execute it in the command line below. There is a pitfall here. Since sonar will scan our class files in the target directory, we need to package the project first.

mvn -package

Then scan again. After the scan is complete, return to localhost:9000 and you can see the quality problems in our code.

Note: The latest version (5.7 and above) of SonarQube no longer supports MySQL. It is recommended to use other databases or use version 5.2

This is the end of this article about how to use docker to build sonarqube. For more information about building sonarqube with docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker builds the code detection platform SonarQube and detects the process of Maven projects

<<:  Repair solution for inconsistent MySQL GTID master and slave

>>:  JavaScript Composition and Inheritance Explained

Recommend

How to implement horizontal bar chart with percentage in echarts

Table of contents Example Code Rendering Code Ana...

JavaScript implements the detailed process of stack structure

Table of contents 1. Understanding the stack stru...

Detailed explanation of MySQL information_schema database

1. Overview The information_schema database is th...

Using zabbix to monitor the ogg process (Linux platform)

The ogg process of a database produced some time ...

Calling the search engine in the page takes Baidu as an example

Today, it suddenly occurred to me that it would be...

The implementation principle of Tomcat correcting the JDK native thread pool bug

To improve processing power and concurrency, Web ...

MySQL Oracle and SQL Server paging query example analysis

Recently, I have done a simple study on the data ...

Docker image creation Dockerfile and commit operations

Build the image There are two main ways to build ...

Detailed steps to configure MySQL remote connection under Alibaba Cloud

Preface As we all know, by default, the MySQL ins...

10 Website Usability Tips Everyone Should Know

Let’s not waste any more time and get straight to...

Basic usage examples of Vue named slots

Preface Named slots are bound to elements using t...

Example code for implementing div concave corner style with css

In normal development, we usually use convex roun...

43 Web Design Mistakes Web Designers Should Watch Out For

This is an article about website usability. The a...

Solution for Nginx installation without generating sbin directory

Error description: 1. After installing Nginx (1.1...