DB migration perform each startup

Good morning,

I’m trying to run Sonarqube on a standalone server using Docker:

  • sonarqube:9-community with jdbc driver installed
  • after:15
  • nginx:latest as reverse proxy

Data directories are volumes mapped to the file system.

the first start goes well, there are no errors in the logs and the system recognizes the presence of Postgres :

sonarqube | 2023.06.09 07:55:13 INFO web[][o.sonar.db.Database] Create JDBC data source for jdbc:postgresql://db:5432/sonar
[...]
sonarqube | 2023.06.09 07:55:15 INFO web[][o.s.s.p.d.m.AutoDbMigration] Automatically perform DB migration on fresh install
sonarqube | 2023.06.09 07:55:15 INFO web[][DbMigrations] Executing DB migrations...
sonarqube | 2023.06.09 07:55:15 INFO web[][DbMigrations] #1 'Create initial schema'...
sonarqube | 2023.06.09 07:55:16 INFO web[][DbMigrations] #1 'Create initial schema': success | time=1013ms

When the server is ready, then I can change the admin password and configure the service.

If I stop the containers and restart them, everything is preserved.
on the other hand, if I destroy them (docker-compose down) I lose all the data and the database migration task is automatically performed… Looks like Sonar doesn’t use Postgres and use its internal H2 database.

Here my docker-compose.yml file :

version: "3"
services:

  proxy:
    image: nginx
    container_name: nginx
    depends_on:
      - sonarqube
    ports:
      - "443:443"
    volumes:
      - /srv/sonarqube/conf/nginx/nginx.conf:/etc/nginx/nginx.conf
      - /srv/sonarqube/ssl:/etc/nginx/certs:ro

  sonarqube:
    image: sonarqube:9-community
    container_name: sonarqube
    depends_on:
      - db
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 262144
        hard: 262144
    volumes:
      - /srv/sonarqube/conf/sonarqube:/opt/sonarqube/conf
      - /srv/sonarqube/data/sonarqube_data:/opt/sonarqube/data
      - /srv/sonarqube/data/sonarqube_extensions:/opt/sonarqube/extensions
      - /srv/sonarqube/logs:/opt/sonarqube/logs

  db:
    image: postgres:15
    container_name: sonar-postgres
    environment:
      POSTGRES_USER: \<POSTGRES_USER>
      POSTGRES_PASSWORD: \<POSTGRES_PASSWORD>
    volumes:
      - /srv/sonarqube/data/postgres:/var/lib/postgresql

Thanks for your help, I don’t understand what’s going wrong.

Hey there.

Take a look at this example docker compose file which includes an environment block pointing to the Postgres database.

Hi Colin

Thank you for your reply.

I tried modifying my configuration according to the example, but it didn’t change anything.
As Postrges is well loaded at startup, I looked on the side of the configuration of the sonar-postgres container.
The docker inspect command allowed me to see that the container was using another volume than the one configured in the docker-compose in /var/lib/docker…
This volume was therefore destroyed and recreated each time the containers were destroyed.
The problem was solved by changing the volume configuration of the postgres container with this :

     volumes:
       - /srv/sonarqube/data/postgres:/var/lib/postgresql/data

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.