Docker creates its own network, with a separate IP space (usually something in the RFC1918 range, 172.16, 192.168, etc.) and by inside this network, there’s also a docker immanent DNS resolver which helps with resolving container names to the docker IP addresses. Creating a CNAME record in your DNS server will not help here, the problem seems to be that either the containers are in different networks (you can create multiple independent networks on the same system, they’re identified by names in the docker compose files) or the docker name service is not working which prevents the correct name resolution.
You did run the curl command from within the mattermost application container, not from the outside, right? Because when the message changes to (52), it basically means that the connection to the database is successful (at least on a TCP level).
You can use the following command to get a list of your docker container names (+ aliases) as well as their IP addresses. Here’s an example of my demo setup:
# docker ps --format "{{.ID}}" | xargs docker inspect | jq '.[].NetworkSettings.Networks'
{
"mattermost": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"mm-740-mattermost-1",
"mattermost",
"3047989d8523"
],
"NetworkID": "9a10035544e09289bcf7b29d8690d73ae357c1517ba5749a58cd11ce2bb6e4cc",
"EndpointID": "16ef5d4d8a6fd7865ffc673dbeb6b1033adc0af87140f886d9a033429bf6ddec",
"Gateway": "192.168.208.1",
"IPAddress": "192.168.208.3",
"IPPrefixLen": 20,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:c0:a8:d0:03",
"DriverOpts": null
}
}
{
"mattermost": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"mm-740-postgres-1",
"postgres",
"5028ca3e028d"
],
"NetworkID": "9a10035544e09289bcf7b29d8690d73ae357c1517ba5749a58cd11ce2bb6e4cc",
"EndpointID": "799d7eca11b7b848e6e330785db1e52f585c9f654fa7193ef5a1aa3717b147c3",
"Gateway": "192.168.208.1",
"IPAddress": "192.168.208.2",
"IPPrefixLen": 20,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:c0:a8:d0:02",
"DriverOpts": null
}
}
My mattermost application container in this scenario has the alias “mattermost” (as well as “mm-740-mattermost-1”) and the database container has the alias “postgres”. You can also see the IP addresses in this output, so for testing purposes you could change the hostname postgres
in the MM_SQLSETTINGS_DATASOURCE
to the IP address of your postgres container (make sure to only restart the mattermost application container then, not the postgres container) and see if that changes anything.