Question: Sonarqube official docker image, is not persisting any configuration changes like: `creating users, changing root password or even installing new plugins`. 

Once the container is restarted, all the configuration changes disappear and the installed plugins are lost. Even the projects' keys and their previous QA analytics data is unavailable after a restart. 

How can we persist the data when using Sonarqube's official docker image?

Answer: 
Hi @VanagaS and others landing here.

I just wanted to provide an alternative to the above. Maybe some would even consider it an easier one.

Notice this line [SONARQUBE\_HOME](https://github.com/SonarSource/docker-sonarqube/blob/442f950dae232fca8e1e919e017270971cee46f6/4.5.6/Dockerfile#L5) in the Dockerfile for the `docker-sonarqube` image. We can control this environment variable.

When using `docker run`. Simply do:

`txt
docker run -d \
...
...
-e SONARQUBE_HOME=/sonarqube-data
-v /PERSISTENT_DISK/sonarqubeVolume:/sonarqube-data`

This will make Sonarqube create the conf, data and so forth folders and store data therein. As needed.

---

Or with `Kubernetes`. In your deployment YAML file. Do:

`txt
...
...
env:
- name: SONARQUBE_HOME
 value: /sonarqube-data
...
...
volumeMounts:
- name: app-volume
 mountPath: /sonarqube-data`

And the `name` in the `volumeMounts` property points to a volume in the `volumes` section of the Kubernetes deployment YAML file.
This again will make Sonarqube use the `/sonarqube-data` mountPath for creating extenions, conf and so forth folders, then save data therein.

And voila your Sonarqube data is thereby persisted. 

I hope this will help others.

N.B. Notice that the YAML and Docker run examples are not exhaustive. They focus on the issue of persisting Sonarqube data.
Since Sonarqube v7.9 , Mysql is not supported. One needs to use postgresql. Install Postgresql and configure to run on host ip rather than localhost, private ip is preferred.

Reference: <https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04>

```
postgres=# create database sonar;
postgres=# create user sonar with encrypted password 'mypass';
postgres=# grant all privileges on database sonar to sonar;

```

create a directory on host
==========================

```
mkdir /server_data/sonarqube/extensions
mkdir /server_data/sonarqube/data # this will be useful in saving startup time

```

Start the container
===================

docker run -d   

--name sonarqube   

-p 9000:9000   

-e SONARQUBE\_JDBC\_USERNAME=sonar   

-e SONARQUBE\_JDBC\_PASSWORD=mypass   

-e SONARQUBE\_JDBC\_URL=jdbc:postgresql://{host/private ip only}:5432/sonar   

-v /server\_data/sonarqube/data:/opt/sonarqube/data   

-v /server\_data/sonarqube/extensions:/opt/sonarqube/extensions   

sonarqube

You may face this error when you do "docker logs container\_id"

> 
> ERROR: [1] bootstrap checks failed [1]: max virtual memory areas
> vm.max\_map\_count [65530] is too low, increase to at least [262144]
> 
> 
> 

This is the fix, run on your host

```
sysctl -w vm.max_map_count=262144

```

In order to add hostname
edit `/etc/postgresql/10/main/postgresql.conf`

In order to add docker as client for postgres edit `/etc/postgresql/10/main/pg_hba.conf`

10 - postgres version used