Skip to content

kamyargerami/matrix-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ScreenShot

Setup Matrix with docker-compose

This repository helps you run your messaging application.

You can set up all you need for the matrix in less than an hour. It will install the following applications for you.

  • Synapse
  • Element
  • PostgreSQL
  • Coturn
  • Nginx
  • Traefik

Requirements

  • Docker
  • Docker-compose

Setup DNS records

You need to have a domain; and you need to add two subdomains (A record) to it.

example.com
matrix.example.com
web.example.com

Automatic Installation

You can simply setup the matrix with all dependencies using below command: (We recommend using Ubuntu server for high compatibility)

sudo bash setup.sh <your-domain.com> <your-server-ip> <postgres-password>

Well done! Read the Testing section :)

Manual Installation

If you like to do all the actions by yourself follow these steps:


  1. Clone the repository and go to the matrix directory

  1. Copy .env.example to .env and change DOMAIN in .env file to your domain

  1. Run docker-compose up and after 1 minute stop it to do the next action.

  1. Edit the /var/lib/docker/volumes/matrix_nginx_conf/_data/default.conf and add these lines in the bottom of the file before }, then change the example.com to your domain.
    location /.well-known/matrix/server {
        access_log off;
        add_header Access-Control-Allow-Origin *;
        default_type application/json;
        return 200 '{"m.server": "matrix.example.com:443"}';
    }

    location /.well-known/matrix/client {
        access_log off;
        add_header Access-Control-Allow-Origin *;
        default_type application/json;
        return 200 '{"m.homeserver": {"base_url": "https://matrix.example.com"}}';
    }

  1. Edit the /var/lib/docker/volumes/matrix_coturn/_data/turnserver.conf and add the below configuration:
  • Replace the LongSecretKeyMustEnterHere with a secure random password.
  • Replace matrix.example.com with your domain
  • Change the YourServerIP to your server's public IP address.
use-auth-secret
static-auth-secret=LongSecretKeyMustEnterHere
realm=matrix.example.com
listening-port=3478
tls-listening-port=5349
min-port=49160
max-port=49200
verbose
allow-loopback-peers
cli-password=SomePasswordForCLI
external-ip=YourServerIP

  1. Change the example.com with your domain in the below command and run it
docker run -it --rm -v matrix_synapse_data:/data -e SYNAPSE_SERVER_NAME=example.com -e SYNAPSE_REPORT_STATS=yes matrixdotorg/synapse:latest generate

  1. Edit /var/lib/docker/volumes/matrix_synapse_data/_data/homeserver.yaml file and change it as below:
  • You need to replace the database config with PostgreSQL

Don't worry about the database security, this is not going to be exposed to the internet.

database:
  name: psycopg2
  txn_limit: 10000
  args:
    user: synapse
    password: aComplexPassphraseNobodyCanGuess
    database: synapse
    host: synapse_db
    port: 5432
    cp_min: 5
    cp_max: 10
  • Add below configuration to the end of the file
  • Change all example.com to your domain address.
  • Change LongSecretKeyMustEnterHere to the secret key that you chose before in /var/lib/docker/volumes/matrix_coturn/_data/turnserver.conf
turn_uris:
  - "turn:matrix.example.com:3478?transport=udp"
  - "turn:matrix.example.com:3478?transport=tcp"
  - "turns:matrix.example.com:3478?transport=udp"
  - "turns:matrix.example.com:3478?transport=tcp"
turn_shared_secret: "LongSecretKeyMustEnterHere"
turn_user_lifetime: 86400000
turn_allow_guests: False

  1. By default, registration is disabled, and users must be added using the command line. If you want to allow everybody to register in your matrix, you can add the below line to the end of /var/lib/docker/volumes/matrix_synapse_data/_data/homeserver.yaml file.
enable_registration: true
enable_registration_without_verification: true

If you need to have email verification enabled or a captcha on registration, you can read the link below:

https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html#registration


  1. Configure the Element to use your homeserver address by default

Element uses matrix.org as default homeserver, if you are not able to access matrix.org , the element shows white screen and it loads after 60 seconds.

Edit /var/lib/docker/volumes/matrix_element/_data/config.json and change the url at line 4 to your domain

"base_url": "https://matrix.example.com"

  1. Run the containers with docker-compose up and if everything goes well, stop them and run the docker-compose up -d to run these containers in the background.

  1. Add new user

Run the below command to create a user.

docker exec -it matrix_synapse_1 register_new_matrix_user -c /data/homeserver.yaml http://localhost:8008

Testing

  1. The matrix URL (https://matrix.example.com) must show the synapse default page
  2. Nginx must respond to these two URLs
  3. You can test the federation on the link below
  4. You can log in to your Element client at https://web.example.com

For more information, you can watch the tutorials.

https://www.youtube.com/watch?v=JCsw1bbBjAM

https://matrix.org/docs/guides/understanding-synapse-hosting

https://gist.github.com/matusnovak/37109e60abe79f4b59fc9fbda10896da?permalink_comment_id=3626248#optional-turn-server-video-calls

Stop services

It's just stop containers

docker-compose -f matrix/docker-compose.yml down

You can run services again with

docker-compose -f matrix/docker-compose.yml up -d

Stop services with DELETE all matrix data

It will removes docker containers with all volumes

docker-compose -f matrix/docker-compose.yml down -v

About

Deploy matrix with all dependencies using docker-compose

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages