Postgres - cannot ping db

Summary
I’m trying to use external database with Mattermost 6.1.0, but I always fail with {"timestamp":"2021-11-29 20:24:12.488 Z","level":"error","msg":"Failed to ping DB","caller":"sqlstore/store.go:272","error":"dial tcp 127.0.0.1:5432: connect: connection refused","retrying in seconds":10}

It seems the app is not loading my config file DataSource configuration but always uses local setup because it says dial tcp 127.0.0.1:5432: connect: connection refused not dial tcp MY-URL:5432: connect: connection refused.

When I use AWS RDS database, local database running on a port or any other database source, I always get the same error.

Steps to reproduce

~ $ ping mattermost_postgres
PING mattermost_postgres (172.18.0.4): 56 data bytes
ping: permission denied (are you root?)
~ $ ^C
~ $ cat /mattermost/config/config.json | grep DataSource
        "DataSource": "postgres://postgres:postgres@mattermost_postgres/postgres?sslmode=disable\u0026connect_timeout=10",
        "DataSourceReplicas": [],
        "DataSourceSearchReplicas": [],
~ $ mattermost -c /mattermost/config/config.json 
{"timestamp":"2021-11-29 20:30:04.312 Z","level":"info","msg":"Server is initializing...","caller":"app/server.go:253","go_version":"go1.16.7"}
{"timestamp":"2021-11-29 20:30:04.312 Z","level":"info","msg":"Starting websocket hubs","caller":"app/web_hub.go:93","number_of_hubs":16}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":6}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":2}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"info","msg":"Pinging SQL","caller":"sqlstore/store.go:262","database":"master"}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":0}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":3}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":1}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":8}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":11}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":4}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":5}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":13}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":10}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":9}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":15}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":7}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":14}
{"timestamp":"2021-11-29 20:30:04.313 Z","level":"debug","msg":"Hub is starting","caller":"app/web_hub.go:410","index":12}
{"timestamp":"2021-11-29 20:30:04.314 Z","level":"error","msg":"Failed to ping DB","caller":"sqlstore/store.go:272","error":"dial tcp 127.0.0.1:5432: connect: connection refused","retrying in seconds":10}

Expected behavior
Connect to the database, or, at least show error with the right connection IP address:

DB","caller":"sqlstore/store.go:272","error":"dial tcp 172.18.0.4:5432: connect: connection refused","retrying in seconds":10}

Observed behavior
Connecting always to localhost.