How to Set Up Matrix/Synapse Server with Docker
WARNING: Please note that this guide is a summary of the commands used in the video tutorial. It's not a step-by-step tutorial itself. For detailed instructions, please refer to the video tutorial.
Install Docker
Add Docker’s official GPG key:
apt-get update
apt-get install ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
Add Docker repository to apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
Install Docker and other required packages:
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose docker-compose-plugin nano
Install Matrix with Docker
Create docker-compose.yml
nano docker-compose.yml
Paste the lines below in the docker-compose.yml
version: '3'
services:
matrix:
image: matrixdotorg/synapse:latest
ports:
- "8008:8008"
- "8448:8448"
volumes:
- ./data:/data
environment:
- SYNAPSE_SERVER_NAME=<REPLACE.WITH.YOUR_DOMAIN_NAME>
- SYNAPSE_REPORT_STATS=no
restart: always
Generate Matrix container configuration
docker-compose run --rm matrix generate
Edit the homeserver.yml file in data directory and add the following configuration for TLS and registration:
- port: 8448
tls: true
type: http
x_forwarded: true
resources:
- names: [client, federation]
compress: false
tls_certificate_path: "/data/cert.pem"
tls_private_key_path: "/data/key.pem"
enable_registration: true
enable_registration_without_verification: true
Upload you ssl/tls key and full chain files to data directory and chnage permissions so your container has rights to access the two files.
Start your Matrix server:
docker-compose up -d
Useful Commands
Create admin user:
register_new_matrix_user -c /data/homeserver.yaml
Restart Matrix container:
docker-compose restart matrix
Access your container CLI:
docker exec -it <container_id> /bin/bash