Introduction: SonarQube is an open-source platform developed by SonarSource for continuous inspection of code quality. It helps developers write cleaner, safer, and more reliable code by analyzing and detecting code smells, bugs, security vulnerabilities, and other quality issues. Docker Compose is a tool for defining and running multi-container Docker applications. By combining SonarQube with Docker Compose, you can easily set up and manage SonarQube instances in your development environment. In this guide, we will walk through the step-by-step process of installing SonarQube using Docker Compose on Ubuntu 22.04.
Prerequisites: Before proceeding with the installation, ensure that you have the following prerequisites:
- Ubuntu 22.04 installed on your system.
- Docker and Docker Compose are installed on your Ubuntu system
Commands
$ sudo apt update
$ sudo apt upgrade -y
$ sudo apt install docker.io docker-compose -y
$ systemctl status docker
$ docker-compose --version
$ sudo usermod -aG docker $USER
$ newgrp docker
$ mkdir sonarqube
$ cd sonarqube
$ nano docker-compose.yml
==================================================================================
version: '3'
services:
sonarqube:
image: sonarqube:latest
container_name: sonarqube
ports:
- "9000:9000"
- "9092:9092"
environment:
- SONARQUBE_JDBC_USERNAME=sonarqube
- SONARQUBE_JDBC_PASSWORD=sonarqube
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
networks:
- sonarnet
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
db:
image: postgres:latest
container_name: postgres
environment:
- POSTGRES_USER=sonarqube
- POSTGRES_PASSWORD=sonarqube
networks:
- sonarnet
volumes:
- postgresql:/var/lib/postgresql
networks:
sonarnet:
driver: bridge
volumes:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
postgresql:
====================================================================================
$ docker-compose up -d
Video: How to Install SonarQube using Docker Compose on Ubuntu 22.04