Docker maps Postgres twice

I am not very sure where to ask this question as it is related to self hosting SonarQube and the Docker Doc:

It links to docker-sonarqube/example-compose-files/sq-with-postgres at master · SonarSource/docker-sonarqube · GitHub, which maps PostGres like so:

volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data
  • Mounting both postgresql and postgresql_data on overlapping paths is not standard.
  • The only valid persistent path for official Postgres images is AFAIK /var/lib/postgresql/data

It would, further, be much better to host map the data, so in case of a unexpected Docker failure we have the DB saved.

Doc also says we have to docker volume create the volumes… which again AFAIK is not something required. I run dockers all the time and the volumes inside docker are always taken care of by docker. Usually, it even creates host side volumes, however there I can agree they should be first created so they are not owned by root.

What do I miss?

Dear @smileBeda,

Thanks for posting back on our Community Forum and providing such a good suggestion!

It would, further, be much better to host map the data, so in case of a unexpected Docker failure we have the DB saved.

You raised an important improvement to make on our examples! Quoting the PostgreSQL maintainers, “the PGDATA environment variable of the image was changed to be version specific in PostgreSQL 18 and above⁠. For 18 it is /var/lib/postgresql/18/docker. Later versions will replace 18 with their respective major version (e.g., /var/lib/postgresql/19/docker for PostgreSQL 19.x)”.

We defined a ticket (SONAR-25775) that makes this change visible in our examples to ensure a smooth upgrade to PostgreSQL 18 in the next iterations.

Doc also says we have to docker volume create the volumes…

This part of the docs is meant to be used when our Docker users do not leverage docker compose for other use cases.