How can we prevent the SonarQube settings from being reset when updating the Docker image?

Version: 8.6 (Docker image)
When upgrading to a newer Docker image (for example from 8.5 to 8.6) I noticed that our settings of SonarQube had been reset.

We run SonarQube with docker-compose, which is as follows:

...
sonarqube_database:
        image: postgres:9.6
        restart: unless-stopped
        environment:
                - "POSTGRES_USER=sonar"
                - "POSTGRES_PASSWORD=oursupersecretpassword"
sonarqube:
        image: sonarqube:8.6-developer
        restart: unless-stopped
        environment:
                - "SONAR_JDBC_URL=jdbc:postgresql://sonarqube_database:5432/sonar"
                - "SONAR_JDBC_USERNAME=sonar"
                - "SONAR_JDBC_PASSWORD=oursupersecretpassword"
        volumes:
                - sonarqube_extensions:/opt/sonarqube/extensions
                - sonarqube_data:/opt/sonarqube/data
                - sonarqube_data:/opt/sonarqube/logs
...

I thought by using volumes I could avoid this problem, but it doesn’t seem to matter.
How can I avoid this problem? Because I don’t look forward to setting up SonarQube everytime I upgrade to a new version. And I would like to keep the history.

Hey there.

Your database is probably being destroyed and recreated – so that’s what you ought to focus on preserving (that’s where all settings and project data are stored)

Is SonarQube able to handle this automatically or do I manually need to backup the database and restore it after upgrade?

This is all a Docker/Postgres matter – SonarQube just connects where it’s told. You might find StackOverflow posts like these helpful