[Solved] Docker setup: mattermoset tries to connect to wrong postgres container

Mattermost docker config does not seem to properly handle MM_SQLSETTINGS_DATASOURCE when pointing to a container/hist other than “postgres”

Steps to reproduce
On the host I’m trying to deploy mattermost, I already have an existing postgres container running (named “postgres”) When I first spun up mattermost, it tried and failed to connect to that container - i.e. in the logs, I saw that it used the docker network IP of that pre-existing postgres container.

So I saw this and modified my setup accordingly:



    image: postgres:${POSTGRES_IMAGE_TAG}
      - postgres_mattermost

(I also deleted all pertinent volume dirs from previous starts)

What I see in the mattermost container log now though is this:

   {"timestamp":"2023-10-09 17:02:59.530 +02:00","level":"error","msg":"Failed to ping DB","caller":"sqlstore/store.go:252","error":"dial   │
│    tcp connect: connection refused","retrying in seconds":10} is obviously wrong.

Expected behavior
With MM_SQLSETTINGS_DATASOURCE set as above, I’d excpect it to connect to my postgres_mattermost container.

Observed behavior
See above

Ok, I’m obviously stupid, the proper MM_SQLSETTINGS_DATASOURCE is postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres_mattermost:5432/${POSTGRES_DB}?sslmode=disable&connect_timeout=10
when pointing to a container named postgres_mattermost

Case closed

1 Like

Woot! Thanks so much for following up to let us know, Arminus!