# Installing SonarQube from the Docker image

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

We recommend using [Docker Engine](https://docs.docker.com/engine/) version 20.10 and above.

Follow these steps for your first installation:

## Create volumes to persist data <a href="#create-volumes" id="create-volumes"></a>

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 the embedded H2 database and 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:

```css-79elbk
$> docker volume create --name sonarqube_data
$> docker volume create --name sonarqube_logs
$> docker volume create --name sonarqube_extensions
```

{% hint style="warning" %}
Make sure you’re using [**volumes**](https://docs.docker.com/storage/volumes/) as shown with the above commands, and not [**bind mounts**](https://docs.docker.com/storage/bind-mounts/). Using bind mounts prevents plugins from populating correctly.
{% endhint %}

## Add the JDBC driver (if using an Oracle database) <a href="#add-jdbc-driver" id="add-jdbc-driver"></a>

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:

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

b. Exit once SonarQube has started properly.

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

## Start the SonarQube container <a href="#start-container" id="start-container"></a>

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 [Environment variables](/sonarqube-server/10.3/setup-and-upgrade/configure-and-operate-a-server/environment-variables.md) for more details.

There is more information about installing and updating SonarQube plugins inside your Docker volume found on the [Install a plugin](/sonarqube-server/10.3/setup-and-upgrade/install-a-plugin.md) page.

### Starting the container by using docker run <a href="#starting-the-container-by-using-docker-run" id="starting-the-container-by-using-docker-run"></a>

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

```css-79elbk
$> 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>
```

### Starting the container by using Docker compose <a href="#starting-the-container-by-using-docker-compose" id="starting-the-container-by-using-docker-compose"></a>

{% hint style="info" %}
Unless you intend to delete the database and start new when running your image ,be careful not to use `-v` to `docker-compose down` and, be careful when running commands like `docker system prune` or `docker volume prune`; regardless if you use an `external: true` parameter, your database volumes will not persist beyond the initial startup and shutdown of SonarQube.
{% endhint %}

If you’re using [Docker Compose](https://docs.docker.com/compose/), use the following example as a reference when configuring your `.yml` file. Click the heading below to expand the `.yml` file.

{% hint style="info" %}
The example below will use the latest version of the SonarQube Docker image. If want to use the LTS version of SonarQube, you need to update the example with the `sonarqube:lts-community` image tag.
{% endhint %}

<details>

<summary>Docker Compose .yml file example</summary>

```css-79elbk
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

volumes:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_logs:
  postgresql:
  postgresql_data:
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-server/10.3/setup-and-upgrade/install-the-server/installing-sonarqube-from-docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
