Mattermost Environment is not taken into account

Summary
Mattermost does not read variables from mattermost.environment.

Steps to reproduce

  1. Mattermost in a docker container: 5.39.3
  2. Configuration stored in database, no config.json file available
  3. Create mattermost.environment file in /opt/mattermost/config/mattermost.environment, file content (redacted):
MM_CONFIG='postgres://mattermost:pass@db_host:5432/mattermost?sslmode=disable&connect_timeout=10'
  1. Start mattermost

Expected behavior
According to the docs Configuration in the Mattermost Database — Mattermost documentation mattermost should be able to read MM_CONFIG variable from the file mattermost.environment and read DB connection details from it.

Observed behavior
Mattermost does not read mattermost.environment file. If MM_CONFIG is defined in the file, then mattermost fails to start:

{"level":"error","ts":1641771548.7661307,"caller":"sqlstore/store.go:320","msg":"Failed to ping DB","error":"dial tcp 127.0.0.1:5432: connect: connection refused","retrying in seconds":10}

Checking DB string with command line::

bash-5.1$ bin/mattermost config get SqlSettings.DataSource
SqlSettings.DataSource: "postgres://mmuser:mostest@localhost/mattermost_test?sslmode=disable&connect_timeout=10"

which is the default.
When MM_CONFIG variable is exported in shell enviornment, mattermost starts as expected.