9-BoNUS
Unknown
SonarQube
Cicd Integration

Docker Compose Configuration for SonarQube

Working Configuration

version: "3"
services:
  sonarqube:
    image: sonarqube:community
    depends_on:
      - db
    environment:
      SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
      SONAR_JDBC_USERNAME: sonar
      SONAR_JDBC_PASSWORD: sonar
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
    ports:
      - "9000:9000"
  db:
    image: postgres:12
    environment:
      POSTGRES_USER: sonar
      POSTGRES_PASSWORD: sonar
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data
  set_vm_max_map_count:
    image: alpine:latest
    privileged: true
    command: sh -c "sysctl -w vm.max_map_count=262144"
    depends_on:
      - sonarqube  # Ensure this runs after the SonarQube container
 
volumes:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_logs:
  postgresql:
  postgresql_data:

Configuration Details

  • SonarQube Service (sonarqube):

    • image: Uses the SonarQube Community edition Docker image.
    • depends_on: Ensures that the PostgreSQL container (db) starts before SonarQube.
    • environment:
      • SONAR_JDBC_URL: JDBC connection URL for PostgreSQL.
      • SONAR_JDBC_USERNAME and SONAR_JDBC_PASSWORD: Credentials for PostgreSQL.
    • volumes: Mounts volumes for SonarQube data, extensions, and logs.
    • ports: Exposes port 9000 to access SonarQube.
  • PostgreSQL Service (db):

    • image: Uses the PostgreSQL Docker image.
    • environment:
      • POSTGRES_USER and POSTGRES_PASSWORD: Credentials for PostgreSQL.
    • volumes: Mounts volumes for PostgreSQL data.
  • Set VM Max Map Count Service (set_vm_max_map_count):

    • image: Uses an Alpine image to adjust the vm.max_map_count system setting.
    • privileged: Runs with privileged mode to modify system settings.
    • command: Sets the vm.max_map_count parameter required by SonarQube.
    • depends_on: Ensures this service runs after the SonarQube container.

Troubleshooting Memory Issues

  • Error: If the configuration with set_vm_max_map_count fails due to memory issues or other problems, you may need to adjust the system settings directly on your host machine or ensure that the privileged mode is properly supported in your environment.

Additional Notes

  • Memory Issues: Ensure your Docker daemon has enough memory allocated. If you encounter memory issues, adjust Docker's resource limits or your host system’s memory settings.
  • System Requirements: SonarQube requires specific system settings for performance, such as vm.max_map_count. This setting helps with Elasticsearch performance, which SonarQube uses internally.

Feel free to adjust the configurations based on your specific environment and requirements.


💬 Need a Quick Summary?

Hey! Don't have time to read everything? I get it. 😊
Click below and I'll give you the main points and what matters most on this page.
Takes about 5 seconds • Uses Perplexity AI