Schemaspy in gitlab CI

I’m trying to add schemaspy to .gitlab-ci.yml in order to automatically generate postgres database physical model. However, schemaspy docker container cannot find the postgres service (even though it can be found by other containers).

Here’s my configuration:

image: docker:18.09.5

stages:
  - build

schemaspy:
  stage: build
  services:
    - postgres:latest
    - docker:dind
  variables:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: databasename
  script:
    - mkdir schemaspy
    - docker run -i -v "${PWD}/schemaspy:/output" schemaspy/schemaspy:latest -u "${POSTGRES_USER}" -p "${POSTGRES_PASSWORD}" -host postgres -p 5432 -db "${POSTGRES_DB}" -t pgsql -hq -debug
  artifacts:
    paths:
      - schemaspy/*

And this is the error I get:

org.schemaspy.input.dbms.exceptions.ConnectionFailure: Failed to connect to database URL [jdbc:postgresql://postgres/coredb] The connection attempt failed.