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_USERNAMEandSONAR_JDBC_PASSWORD: Credentials for PostgreSQL.
volumes: Mounts volumes for SonarQube data, extensions, and logs.ports: Exposes port9000to access SonarQube.
-
PostgreSQL Service (
db):image: Uses the PostgreSQL Docker image.environment:POSTGRES_USERandPOSTGRES_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 thevm.max_map_countsystem setting.privileged: Runs with privileged mode to modify system settings.command: Sets thevm.max_map_countparameter 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_countfails due to memory issues or other problems, you may need to adjust the system settings directly on your host machine or ensure that theprivilegedmode 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.