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

Div picture marquee seamless connection implementation code

Copy code The code is as follows: <html> &l...

Detailed installation and uninstallation tutorial for MySQL 8.0.12

1. Installation steps for MySQL 8.0.12 version. 1...

Use viewport in meta tag to define screen css

<meta name="viewport" content="w...

7 native JS error types you should know

Table of contents Overview 1. RangeError 2. Refer...

How to set the border of a web page table

<br />Previously, we learned how to set cell...

Implementation example of uploading multiple attachments in Vue

Table of contents Preface Core code File shows pa...

Table Tag (table) In-depth

<br />Table is a tag that has been used by e...

JavaScript canvas realizes the effect of nine-square grid cutting

This article shares the specific code of canvas t...

Why should css be placed in the head tag

Think about it: Why should css be placed in the h...

Steps to install MySQL using Docker under Linux

As a tester, you may often need to install some s...

Use CSS's clip-path property to display irregular graphics

clip-path CSS properties use clipping to create t...

How to update, package, and upload Docker containers to Alibaba Cloud

This time, we will try to package the running con...