2

I used the following docker-compose file to start-up sonarQube server https://derryberni.medium.com/how-to-setup-sonar-cube-sonar-scanner-with-docker-compose-simple-15c9d84966dc

And in the logs found that everything is up and running

2021.01.31 19:16:54 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory 
/opt/sonarqube/temp
2021.01.31 19:16:54 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 
127.0.0.1:9001, TCP: 127.0.0.1:46495]
2021.01.31 19:16:55 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, 
logFilenamePrefix=es]] from [/opt/sonarqube/elasticsearch]: 
/opt/sonarqube/elasticsearch/bin/elasticsearch
2021.01.31 19:16:55 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2021.01.31 19:17:26 INFO  app[][o.s.a.SchedulerImpl] Process[es] is up
2021.01.31 19:17:26 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[[key='web', ipcIndex=2, 
logFilenamePrefix=web]] from [/opt/sonarqube]: /opt/java/openjdk/bin/java -Djava.awt.headless=true - 
Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube/temp -XX:-OmitStackTraceInFastThrow --add- 
opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add- 
opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -Xmx512m - 
Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dhttp.nonProxyHosts=localhost|127.*|[::1] -cp 
./lib/common/*:/opt/sonarqube/lib/jdbc/postgresql/postgresql-42.2.17.jar 
org.sonar.server.app.WebServer /opt/sonarqube/temp/sq-process9044442147466534697properties
2021.01.31 19:19:42 INFO  app[][o.s.a.SchedulerImpl] Process[web] is up
2021.01.31 19:19:42 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[[key='ce', ipcIndex=3, 
logFilenamePrefix=ce]] from [/opt/sonarqube]: /opt/java/openjdk/bin/java -Djava.awt.headless=true - 
Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube/temp -XX:-OmitStackTraceInFastThrow --add- 
opens=java.base/java.util=ALL-UNNAMED -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError - 
Dhttp.nonProxyHosts=localhost|127.*|[::1] -cp 
./lib/common/*:/opt/sonarqube/lib/jdbc/postgresql/postgresql-42.2.17.jar org.sonar.ce.app.CeServer 
 /opt/sonarqube/temp/sq-process10127776924284503599properties
2021.01.31 19:20:00 INFO  app[][o.s.a.SchedulerImpl] Process[ce] is up
2021.01.31 19:20:00 INFO  app[][o.s.a.SchedulerImpl] SonarQube is up

And when trying to hit localhost:9001 no response is displayed

Error:

This page isn’t workinglocalhost didn’t send any data.
ERR_EMPTY_RESPONSE

docker ps result enter image description here

Docker Compose file

version: "3"

services:
  sonarqube:
    image: sonarqube
    expose:
      - 9001
    ports:
      - "127.0.0.1:9001:9001"
    networks:
      - sonarnet
    environment:
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
      - SONARQUBE_JDBC_USERNAME=sonar
      - SONARQUBE_JDBC_PASSWORD=sonar
    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
    networks:
      - sonarnet
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data

networks:
  sonarnet:

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

Any Ideas what is the issue ?

User
  • 573
  • 3
  • 15
  • 28
  • 90% certain the problem is that while elasticsearch is listening on port 9001 on 127.0.0.1 on the defined network, that is not the same as your host machine. Maybe try attaching to one of the containers and try a wget or curl from there (that is just to confirm) – Chris Jan 31 '21 at 20:13
  • Also, isn't it 9000 for Sonarqube? I don't know enough about the setup to see where elasticsearch fits in, but presumably Sonarqube is taking input from elasticsearch but is presenting it's UI on 9000 – Chris Jan 31 '21 at 20:19
  • I changed it to 9001 in the compose file – User Feb 01 '21 at 06:58
  • @Chris, in the pod it self i can ping localhost:9001. How can I access it from my machine ?Any ideas ? – User Feb 01 '21 at 08:21
  • Ah right - I've hit this a few times. Depends how docker is running. If it's on windows and using a VM then you need to hit the IP address of that VM rather than localhost – Chris Feb 01 '21 at 09:00
  • Please show your actual Docker Compose file. Also an output of `docker ps` would be useful. – raspy Feb 01 '21 at 09:06
  • I looked recently at a similar question, https://stackoverflow.com/questions/65657128/how-to-get-adminer-to-run-locally-using-docker/65657296#65657296, but it's not quite the same thing - in the example you are looking at you do have port mapping, but also there is a network defined. I'm at work at the moment else I'd have a play around - I think there is a simple answer but I haven't been looking at Docker for a while so it's not coming to me – Chris Feb 01 '21 at 09:07
  • @raspy i updated my question with Docker Compose file & result if docker ps – User Feb 01 '21 at 10:45

1 Answers1

0

The expose and port mapping is not useful, since Sonarqube listens on port 9000. If you wish to have it available from the host on port 9001, please update your mapping to read 127.0.0.1:9001:9000 - that will make your host respond to port 9001 and forward it to the container to port 9000, where Sonarqube listens.

raspy
  • 3,995
  • 1
  • 14
  • 18
  • Thank you @raspy, it works fine. But it gives me "Authentication failed" . I ma using sonar/sonar as docker compose file – User Feb 01 '21 at 13:44
  • Where do you get this "authentication failed" message? Is it in the UI upon attempting to log in to Sonarqube? – raspy Feb 01 '21 at 13:55
  • Yes, Thanks @raspy it was my mistake – User Feb 01 '21 at 14:38