Matrix: Self-Hosted Secure Communication Platform

18-08-2024 - 1 minute, 31 seconds -
documentation communication matrix docker self-hosted

Setting Up Matrix Synapse with Docker

Introduction

Matrix Synapse is an open-source, real-time communication server designed for decentralized communication. This guide will help you set up Matrix Synapse along with Element (a web frontend) and integrate a Discord bridge using Docker.

Prerequisites

  • Docker and Docker Compose: Ensure Docker and Docker Compose are installed on your system.
  • Domain Configuration: Ensure you have a domain name configured for your Matrix server.

Setting Up Matrix Synapse, Element, and Discord Bridge

1. Create a Docker Compose File

Create a docker-compose.yml file for running Matrix Synapse, Element, and the Discord bridge:

version: "3.3"

services:
  postgresql:
    image: postgres:latest
    container_name: "synapse-postgres"
    restart: unless-stopped
    environment:
      POSTGRES_DB: synapse
      POSTGRES_USER: synapse
      POSTGRES_PASSWORD: ********
      POSTGRES_INITDB_ARGS: "--encoding='UTF8' --lc-collate='C' --lc-ctype='C'"
    volumes:
      - ./postgresdata:/var/lib/postgresql/data

  synapse:
    image: matrixdotorg/synapse:latest
    container_name: "synapse-matrix"
    restart: unless-stopped
    environment:
      SYNAPSE_SERVER_NAME: "matrix.clintmasden.duckdns.org"
      SYNAPSE_REPORT_STATS: "yes"
    ports:
      - "8008:8008"
      - "8448:8448"
    volumes:
      - ./synapse:/data
    depends_on:
      - postgresql

  element:
    image: vectorim/element-web:latest
    container_name: "synapse-element"
    restart: unless-stopped
    ports:
      - "8009:80"
    volumes:
      - ./element-config.json:/app/config.json
    depends_on:
      - synapse

  synapse-discord:
    image: dock.mau.dev/mautrix/discord:latest
    container_name: "synapse-matrix-discord"
    restart: unless-stopped
    ports:
      - "29334:29334"
    volumes:
      - ./synapse-discord:/data
2. Configure Element

Create an element-config.json with the necessary configuration details for your Element installation:

{
  "default_server_config": {
    "m.homeserver": {
      "base_url": "https://matrix.clintmasden.duckdns.org",
      "server_name": "matrix.clintmasden.duckdns.org"
    },
    "m.identity_server": {
      "base_url": "https://vector.im"
    }
  }
}
3. Run Your Docker Compose Configuration

Deploy your setup using:

docker-compose up -d
4. Register a New Matrix User

After deployment, register a new Matrix user to manage the server:

docker exec -it synapse-matrix register_new_matrix_user http://localhost:8008 -c /data/homeserver.yaml -u cmasden -a -p ********

Resources and References

Conclusion

You have successfully set up Matrix Synapse with Element and a Discord bridge, allowing for seamless communication between Matrix and Discord. This setup can be expanded or modified with additional bridges, plugins, or security enhancements.