Start SonarQube from docker Image

Hi Community,

I am trying to start using sonarqube in my projects but I came from QA manual background and so far I am facing lack of technical skills in order to get the docker image running with all plugins I need from the docker hub.

What I am trying to do is to use the latest image released from the docker hub with the sonarqube:latest and install a plugin to evaluate a clojure application. By now all I could do was to use docker compose to run sonaqube with the version I defined, but I can’t use the postgres or install the plugin I desire. What I have so far is this:

Dockerfile

FROM sonarqube:latest

COPY /extensions/sonar-clojure-plugin-2.0.0.jar /opt/sonarqube/extensions/plugins/
COPY /config/sonar.properties /opt/sonarqube/conf/

docker-compose.yml

version: "3.8"
services:
  sonarqube:
    build: .
    container_name: sonarqube6
    ports:
      - "9000:9000"
      - "9002:9002"
    environment:
      - TZ=America/Sao_Paulo
    networks:
      - sonarnet
    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:latest
    container_name: postgres_sonarqube6
    networks:
      - sonarnet
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data

networks:
  sonarnet:
    driver: bridge
    ipam:
      config:
        - subnet: 172.16.57.0/25

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

sonar.properties

sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonar
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

Am I in the right path or what I am trying to do is sth out of this world?

Hi Gustavo, welcome to the SonarSource Community!

I think you’re overcomplicating things and mixing a traditional config strategy with the one we recommend for Docker.

  • Nothing in your use case requires creation of a custom Docker image
  • You should configure your JDBC connectivity via environment variables as described in the link above, rather than trying to insert a modified config file
  • Your postgres connection isn’t working because localhost doesn’t magically resolve to the outer host running Docker when you reference it like this; it’s being interpreted as the container’s VM, which has no database running. If you use the environment variable config as recommended, in your JDBC URL you should be able to reference the database host using the container name db as defined in your docker-compose.yml file.
  • Simply copy the plugins you wish into your sonarqube_extensions volume in the subfolder called “plugins” - a command like docker cp might help here.
  • I am not sure what you are trying to accomplish with the sonarqube_bundled-plugins volume but there’s no need to define this.

I hope this helps.

According to the link posted, Use of the environment variables SONARQUBE_JDBC_USERNAME, SONARQUBE_JDBC_PASSWORD, and SONARQUBE_JDBC_URL is deprecated and will stop working in future releases.

What is the recomended way of configuring the JDBC connection?

Hi @CErnenwein ,

we have a dedicates section about the supported environment variables in our documentation here.
The replacement for the once you mentioned would be:

  • SONAR_JDBC_USERNAME
  • SONAR_JDBC_PASSWORD
  • SONAR_JDBC_URL