dockermatrix-synapse

How to connect Mautrix-WhatsApp bridge in an existing Docker network


I'd like to have Mautrix-WhatsApp bridge on my existing Docker network. Currently my Docker Network has 3 containers, which are Element chat, Matrix Synapse, and Postgresql database. I followed a guide on the Mautrix website regarding how to bridge it to an existing Docker network (https://docs.mau.fi/bridges/general/docker-setup.html?bridge=whatsapp) I've checked the configuration and registration.yaml files and it seems to be correct, however, the problem comes when I try to run the bridge.

The error message that shows up informs me that Mautrix-WhatsApp cannot connect to my existing Postgresql instance. The error message says "cannot connect to myserverIPaddress:5432 connection refused"

I've checked UFW, and opened port 5432 as well, but this doesn't seem to be the problem, as my existing Element chat instance is working without issue.

I suspect it might be an issue with the config.yaml file of the Mautrix-WhatsApp but I haven't had a clue which part. It could also be that the new Mautrix-WhatsApp container should run within my existing Docker network where my Postgresql container is.

What else can I try to solve the port 5432 connection refused for Mautrix-WhatsApp bridge? Any advice is appreciated.

Checked Mautrix-WhatsApp config.yaml, registration.yaml, put the registration file within my existing Matrix Synapse container, checked UFW, already created the database, user, password, and granted the privileges to said user (within the Postgresql container) but I am unsure how to run the Mautrix-WhatsApp bridge to connect it within my existing Docker network, as I suspect this could be why the connection was refused in the first place.


Solution

  • I solved it, the fault is in the database connection in the config.yaml If you want the bridge to run in a Docker container network that has Matrix-Synapse, do not use the URL of your homeserver (i.e. yourDomain.com:5432)

    If running in Docker, The bridge should run within the same Docker network as Matrix, Postgres, and Element, AND The connection to the database should be the name of the Postgres container.

    uri: postgres://mautrix:mautrix@matrix-postgres-1/database?sslmode=disable
    

    In this example where it says "@matrix-postgres-1" this is where you'd place the name of your Postgresql container. If not running on Docker, it would be @localhost. Otherwise, use the name of your Postgresql container in Docker