Start Free
10.7 | Server installation and setup | Installing the server | Installing SonarQube from the Docker image

Installing SonarQube from the Docker image

On this page

SonarQube docker images support running both on the amd64 architecture and on arm64-based Apple Silicon.

We recommend using Docker Engine version 20.10 and above.

First, check the requirements and perform the pre-installation steps. Then follow these steps for your first installation:

Create volumes to persist data

Creating the following volumes helps prevent the loss of information when updating to a new version or upgrading to a higher edition:

    • sonarqube_data: contains data files, such as Elasticsearch indexes
    • sonarqube_logs: contains SonarQube logs about access, web process, CE process, and Elasticsearch
    • sonarqube_extensions: will contain any plugins you install and the Oracle JDBC driver if necessary.

Create the volumes with the following commands: 

$> docker volume create --name sonarqube_data
$> docker volume create --name sonarqube_logs
$> docker volume create --name sonarqube_extensions

Add the JDBC driver (if using an Oracle database)

Drivers for supported databases (except Oracle) are already provided. If you're using an Oracle database, you need to add the JDBC driver to the sonar_extensions volume. To do this:

 a. Start the SonarQube container with the embedded H2 database:

$ docker run --rm \
    -p 9000:9000 \
    -v sonarqube_extensions:/opt/sonarqube/extensions \
    <image_name>

where <image_name> is:

  • for the Community Edition: sonarqube
  • for the other editions: check the tags currently available on the DockerHub page

b. Exit once SonarQube has started properly.

c. Copy the Oracle JDBC driver into sonarqube_extensions/jdbc-driver/oracle.

Start the SonarQube container

Start the SonarQube container:

  • either from the command line (docker run) or 
  • from a configuration file (docker compose). 

For docker-based setups, environment variables supersede all parameters that were provided with properties. See Docker environment variables for more details.

There is more information about installing and updating SonarQube plugins inside your Docker volume found on the Install a plugin page.

Starting the container by using docker run

Run the image with your database properties defined using the -e environment variable flag:

$> docker run -d --name sonarqube \
    -p 9000:9000 \
    -e SONAR_JDBC_URL=... \
    -e SONAR_JDBC_USERNAME=... \
    -e SONAR_JDBC_PASSWORD=... \
    -v sonarqube_data:/opt/sonarqube/data \
    -v sonarqube_extensions:/opt/sonarqube/extensions \
    -v sonarqube_logs:/opt/sonarqube/logs \
    <image_name>

where <image_name> is:

  • for the Community Edition: sonarqube
  • for the other editions: check the tags currently available on the DockerHub page

Starting the container by using Docker compose

If you're using Docker Compose, use the following example as a reference when configuring your .yml file. Click the heading below to expand the .yml file.

Docker Compose .yml file example
services:
  sonarqube:
    image: sonarqube:community
    hostname: sonarqube
    container_name: sonarqube
    read_only: true
    depends_on:
      db:
        condition: service_healthy
    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
      - sonarqube_temp:/opt/sonarqube/temp
    ports:
      - "9000:9000"
  db:
    image: postgres:15
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5
    hostname: postgresql
    container_name: postgresql
    environment:
      POSTGRES_USER: sonar
      POSTGRES_PASSWORD: sonar
      POSTGRES_DB: sonar
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data

volumes:
  sonarqube_data:
  sonarqube_temp:
  sonarqube_extensions:
  sonarqube_logs:
  postgresql:
  postgresql_data:

Was this page helpful?

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License