DEV Community

Raghavvram Johnson
Raghavvram Johnson

Posted on

Host SonarQube Community Edition using Docker Compose

The below is a production-ready docker-compose.yml file to spin up SonarQube Community Build alongside a persistent PostgreSQL database.

docker-compose.yml

services:
  sonarqube:
    image: sonarqube:community
    container_name: sonarqube
    depends_on:
      - db
    ports:
      - "9111:9000"
    networks:
      - sonarnet
    environment:
      - SONAR_JDBC_URL=jdbc:postgresql://db:5432/sonar
      - SONAR_JDBC_USERNAME=sonar
      - SONAR_JDBC_PASSWORD=sonar_secure_password
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
    ulimits:
      nofile:
        soft: 65536
        hard: 65536

  db:
    image: postgres:15-alpine
    container_name: sonarqube_db
    networks:
      - sonarnet
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar_secure_password
      - POSTGRES_DB=sonar
    volumes:
      - postgresql_data:/var/lib/postgresql/data

networks:
  sonarnet:
    driver: bridge

volumes:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_logs:
  postgresql_data:
Enter fullscreen mode Exit fullscreen mode

āš ļø Critical Prerequisite (Elasticsearch Fix)

SonarQube bundles an internal Elasticsearch instance. By default, most host operating systems limit the number of virtual memory map counts, which causes the Sonarqube container to crash immediately on startup.

Before running the compose file, you must run the following command on your host machine to increase this limit:

sudo sysctl -w vm.max_map_count=524288
Enter fullscreen mode Exit fullscreen mode

To make this change permanent, add vm.max_map_count=524288 to your /etc/sysctl.conf file.

How to Start and Access

  1. Start the services in the background:

    docker compose up -d
    
  2. Wait a minute or two for the database migrations to finish, then navigate to http://localhost:9111 in your browser.

  3. Log in using the default credentials:

  • Username: admin
  • Password: admin
  1. You will be immediately prompted to change this default password.

Top comments (0)