Sonarqube - Fail to connect to database

Trying to start Sonarqube as a docker container;

docker run -d --name sonarqube
-p 9000:9000
-e sonar.jdbc.username=sonarqube
-e sonar.jdbc.password=sonarqube
-e sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube
sonarqube

2019.08.05 13:20:39 ERROR web[o.s.s.p.Platform] Web server startup failed
java.lang.IllegalStateException: Fail to connect to database
at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:90)

Database is reachable from the command line.
Any help is appreciated.

Welcome to the community !

if your database is on the docker host, localhost from whithin your SonarQube container refer to the container, not the host.

To refer to the host ip, you can use host.docker.internal :
-e sonar.jdbc.url=jdbc:postgresql://host.docker.internal:5432/sonarqube

You need Docker at least 18.03 to have this feature available.

Hope this help