docker

How to fix database connection error using docker mediawiki image?

I am running media wiki 1.35.2 in a docker container and getting the error

 Original exception: [733e024ba16cc597716794fe] / Wikimedia\Rdbms\DBConnectionError   from line 1420 of /var/www/html/includes/libs/rdbms/loadbalancer/LoadBalancer.php: Cannot access the database: Unknown error ()
 Backtrace:
#0 /var/www/html/includes/libs/rdbms/loadbalancer/LoadBalancer.php(934): Wikimedia\Rdbms\LoadBalancer->reportConnectionError()

LocalSettings.php

$wgDBtype = "postgres"; 
$wgDBserver = "database";
$wgDBname = "my_wiki"; 
$wgDBuser = "wikiuser"; 
$wgDBpassword = "xxx"; 

$wgDBport           = "5432";
//$wgDBmwschema       = "mediawiki";
//$wgDBts2schema      = "public";

I can connect to the database via psql from inside the mediawiki container. The error message is independent from the database type (tried also mariadb – from https://hub.docker.com/_/mediawiki) or even if I shut down the postgresql12 container
I have also tried with IP instead of hostname in LocalSettings.php.

(similar to
Mediawiki with docker. Can’t locate LocalSettings.php and cannot access database)

docker-compose:

mediawiki:
  image: mediawiki:latest
  restart: unless-stopped
  ports:
    - 8080:80
  volumes:
     - /var/www/html/images
    # After initial setup, download LocalSettings.php to the same directory as
    # this yaml and uncomment the following line and use compose to restart
    # the mediawiki service
     - ./wiki/LocalSettings.php:/var/www/html/LocalSettings.php

networks:
  default:
    external:
      name:  ....
  
  (links: is deprecated)