SonarQube is static code analyis tool. It can be installed quickly using Docker-compose with fewer manual steps.SonarQube is an automatic code review tool to detect bugs, vulnerabilities, and code smells in your code. It can integrate with your existing workflow to enable continuous code inspection across your project branches and pull requests. You can follow this link:
What is Docker Compose?
Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down. You can follow this link to know more.
SonarQube using Docker-Compose
Now, We will create a simply docker-compose.yml file and store the code in it.
In this file, We will define all configurations for installing both SonarQube and Postgresql. Open the VIM editor and add the code to it using the below command:
sudo vi docker-compose.yml
version: "3" services: sonarqube: image: sonarqube:6.7.1 container_name: sonarqube restart: unless-stopped environment: - SONARQUBE_JDBC_USERNAME=admin - SONARQUBE_JDBC_PASSWORD=admin - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube ports: - "9001:9000" - "9092:9092" volumes: - sonarqube_conf:/opt/sonarqube/conf - sonarqube_data:/opt/sonarqube/data - sonarqube_extensions:/opt/sonarqube/extensions - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins db: image: postgres:10.1 container_name: db restart: unless-stopped environment: - POSTGRES_USER=admin - POSTGRES_PASSWORD=Admin123 - POSTGRES_DB=sonarqube volumes: - sonarqube_db:/var/lib/postgresql10 - postgresql_data:/var/lib/postgresql10/data volumes: postgresql_data: sonarqube_bundled-plugins: sonarqube_conf: sonarqube_data: sonarqube_db: sonarqube_extensions:
Save the file by entering:wq!
In the above file, I have used two images first for sonarqube and second one for postgresql.
Now execute this compose file using Docker compose command:
sudo docker-compose up -d
Make sure SonarQube is up and running. Run the below command to check the status:
sudo docker-compose logs --follow
Now access sonarQube UI by going to the browser and entering the public DNS name with port 9001. Open any browser and hit the IP with port 9001. You can see in the below picture.
We have covered how to run sonarqube using docker-compose. If you find this blog helpful then like and share it with your friends. Follow this link, To read more blogs of mine.