Deploy Docker Container with SonarQube and Integrate with Jenkins for Code Analysis

Tiempo de lectura: 2 minutos

Reading time: 4 minutes

Today we are going to see how to install SonarQube using a Docker container.

To do this, we will use the following Docker container:

version: "3.1"

services:
  sonarqube:
    image: sonarqube:lts-community
    container_name: sonarqube
    hostname: sonarqube
    ports:
      - 9000:9000
    environment:
      - sonar.jdbc.url=jdbc:postgresql://posgres_db:5432/sonar
      - sonar.jdbc.username=posgres
      - sonar.jdbc.password=adminposgres
      - sonar.search.javaAdditionalOpts=-Dbootstrap.system_call_filter=false
    volumes:
      - ./config/sonarqube/logs:/opt/sonarqube/logs
      - ./config/sonarqube/data:/opt/sonarqube/data
      - ./config/sonarqube/extensions:/opt/sonarqube/extensions

    networks:
      - docker-network

  posgres_db:
    image: postgres:13.1
    container_name: posgres_db
    hostname: posgres_db
    environment:
      - POSTGRES_USER=posgres
      - POSTGRES_PASSWORD=adminposgres
    volumes:
      - ./config/postgres/pg_db:/var/lib/postgresql
      - ./config/postgres/pg_data:/var/lib/postgresql/data
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    networks:
      - docker-network

networks:
  docker-network:
    driver: bridge
    external: true

Now let’s run the code with docker compose up:

docker compose up

If it doesn’t run, we need to set permissions for the /config/sonarqube/ folders.

sudo chmod -R 777 /config/sonarqube/

Once executed, we should be able to access it from http://localhost:9000

It will ask us for a username and password:

By default, they are:

Username: admin

Password: admin

We update the password to a secure one:

Now we add a project, click on add manually:

We enter a name and it will auto-fill the key and we choose which branch we want to deploy our project from:

Leave a Comment