sonarqube

SonarQube with Postgres on docker-compose

Struggling to get a working environment with SonarQube and PostgreSQL?

Use the following docker-compose file and be up and running in minutes.

It is as ‘bare’ as possible:

  • use of official Docker images for both PostgreSQL and SonarQube
  • no other configuration required
  • use of volumes so you can backup your data

Recommended system specs

  • >= 3GB of RAM
# file: docker-compose.yml

version: "3"

services:
  sonarqube:
    image: sonarqube:9.2.1-community
    restart: unless-stopped
    environment:
      - SONARQUBE_JDBC_USERNAME=sonar
      - SONARQUBE_JDBC_PASSWORD=v07IGCFCF83Z95NX
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
    ports:
      - "9000:9000"
      - "9092:9092"
    volumes:
      - sonarqube_conf:/opt/sonarqube/conf
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins

  db:
    image: postgres:13.4
    restart: unless-stopped
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=v07IGCFCF83Z95NX
      - POSTGRES_DB=sonarqube
    volumes:
      - sonarqube_db:/var/lib/postgresql
      # This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
      - postgresql_data:/var/lib/postgresql/data

volumes:
  postgresql_data:
  sonarqube_bundled-plugins:
  sonarqube_conf:
  sonarqube_data:
  sonarqube_db:
  sonarqube_extensions:

Start this stack with the following command:

# start the containers
docker-compose up -d

You can reach your SonarQube instance at http://localhost:9000

Use the default credentials admin/admin to login.

Useful links:

Click Here to Leave a Comment Below

Bruce - 13/03/2018

Is there an error in the ports statement? I could only get this file to work when I commented out the following line:
– “9092:9092”
and then used http://localhost:9000 to access sonarqube.

Reply
    Paul Edenburg - 14/03/2018

    Hi Bruce.

    No, there is no error in the ports statement. Do you get an error-message?

    The only reason I can think of why it fails for you, is that you might have something running on port 9092 already.

    You can check whether the port is free for use with the command netstat -an | grep 9092.

    Having said that, I can’t find in the documentation what port 9092 is used for. It’s not for the front-end, nor for the sonar-scanner to connect to.
    The port is not mentioned in the SonarQube manual,I only find it in it’s Docker image.

    Does it work well for you without mapping port 9092?

    Reply
sarah - 31/05/2018

hello , i get this error :
The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.1.
any suggestion ?

Reply
    Paul Edenburg - 19/06/2018

    Hi Sarah, when do you get this error? I just ran the above to check whether it works and it does.

    Could it be that you already used a named volume ‘postgresql_data’ which you used for another application (which used version 9.6 of PostgreSQL)?

    You could try to change the name of the ‘postgresql_data’ named volume and try again.

    Reply
sarah - 20/06/2018

thank you for you reply ,
i just change the name of the directory but i still have the error when i Downloaded newer image for postgres:10.1

” db_1 | 2018-06-20 14:10:20.497 UTC [1] FATAL: database files are incompatible with server
db_1 | 2018-06-20 14:10:20.497 UTC [1] DETAIL: The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.1

Reply
    Paul Edenburg - 20/06/2018

    Did you run a Docker container earlier with a PostgreSQL (version 9.6)?

    Did you change the named volume both on line 32 and 35?

    Reply
      sarah - 20/06/2018

      yes i did run a docker container earlier and i changed the named volume both

      Reply
        sarah - 20/06/2018

        I GET it now i found same name of the volume used by another container , it works now , thanks 😀

        Reply
          Paul Edenburg - 21/06/2018

          Great that you found it and got it working!
          Good luck with SonarQube!

          Reply
SonarQube for Selenium Tests - 01/01/2019

[…] Under the directory, create a file – docker-compose.yml with below content. [I used this one from this site] […]

Reply
Paul Edenburg - 01/02/2022

Hi @sumanth

Once you’re logged in, go to Administration > Marketplace.
At the bottom of the page you’ll find the plugins you can install.

Reply
Leave a Reply: