Database login failure when creating Sonarqube and PostgreSQL from Docker Compose

Hey guys,

I’ve searched a lot in the forums but haven’t found the exact fix, therefore posting separate question.

The situation is like in the title — I’m trying to create SonarQube and PostgreSQL environment on docker-compose.

My yml file looks like this:

version: "3"


services:
  sonarqube:
    image: sonarqube
    ports:
     - "9000:9000"
     - "5432:5432"
    links:
      - db:db
    environment:
     - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/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
    environment:
     - POSTGRES_USER=sonar
     - POSTGRES_PASSWORD=sonar
     - POSTGRES_DB=sonar
    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:

I start the database separately and everything looks fine.
2019-11-15 15:35:24.268 UTC [1] LOG: database system is ready to accept connections

Then I start the sonarqube container and I get an error
2019-11-15 15:36:25.617 UTC [32] FATAL: password authentication failed for user "sonar"

Although after checking environment settings for the sonarqube container it looks ok:

            "Env": [
                "SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar",
                "PATH=/usr/local/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/local/openjdk-11",
                "JAVA_VERSION=11.0.5",
                "JAVA_BASE_URL=https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases/download/jdk-11.0.5%2B10/OpenJDK11U-jre_",
                "JAVA_URL_VERSION=11.0.5_10",
                "SONAR_VERSION=7.9.1",
                "SONARQUBE_HOME=/opt/sonarqube",
                "SONARQUBE_JDBC_USERNAME=sonar",
                "SONARQUBE_JDBC_PASSWORD=sonar"
            ],

What am I doing wrong here?

Thanks!