2017-09-28 13:12:47 +03:00
# Synapse Docker
2018-05-17 14:44:07 +03:00
The `matrixdotorg/synapse` Docker image will run Synapse as a single process. It does not provide a
database server or a TURN server, you should run these separately.
2018-02-04 17:27:32 +03:00
2018-05-17 14:44:07 +03:00
If you run a Postgres server, you should simply include it in the same Compose
2018-02-04 17:27:32 +03:00
project or set the proper environment variables and the image will automatically
use that server.
2017-09-28 13:12:47 +03:00
## Build
2018-07-17 10:02:45 +03:00
Build the docker image with the `docker-compose build` command.
2017-09-28 13:12:47 +03:00
2018-02-04 17:27:32 +03:00
You may have a local Python wheel cache available, in which case copy the relevant packages in the ``cache/`` directory at the root of the project.
2017-09-28 13:12:47 +03:00
2018-02-04 17:27:32 +03:00
## Run
2017-09-28 13:12:47 +03:00
2018-02-08 23:55:35 +03:00
This image is designed to run either with an automatically generated configuration
file or with a custom configuration that requires manual edition.
### Automated configuration
2018-02-04 17:27:32 +03:00
It is recommended that you use Docker Compose to run your containers, including
this image and a Postgres server. A sample ``docker-compose.yml`` is provided,
2018-02-04 18:18:40 +03:00
including example labels for reverse proxying and other artifacts.
2017-09-28 13:12:47 +03:00
2018-02-08 23:55:35 +03:00
Read the section about environment variables and set at least mandatory variables,
then run the server:
2017-09-28 13:12:47 +03:00
```
2018-02-04 17:27:32 +03:00
docker-compose up -d
2017-09-28 13:12:47 +03:00
```
2018-05-17 14:44:07 +03:00
If secrets are not specified in the environment variables, they will be generated
2018-05-16 12:10:31 +03:00
as part of the startup. Please ensure these secrets are kept between launches of the
Docker container, as their loss may require users to log in again.
2018-02-08 23:55:35 +03:00
### Manual configuration
A sample ``docker-compose.yml`` is provided, including example labels for
2018-05-16 12:10:31 +03:00
reverse proxying and other artifacts. The docker-compose file is an example,
please comment/uncomment sections that are not suitable for your usecase.
2018-02-08 23:55:35 +03:00
Specify a ``SYNAPSE_CONFIG_PATH``, preferably to a persistent path,
to use manual configuration. To generate a fresh ``homeserver.yaml``, simply run:
2017-09-28 13:12:47 +03:00
```
2018-02-08 21:48:53 +03:00
docker-compose run --rm -e SYNAPSE_SERVER_NAME=my.matrix.host synapse generate
2017-09-28 13:12:47 +03:00
```
2018-02-08 23:55:35 +03:00
Then, customize your configuration and run the server:
```
docker-compose up -d
```
### Without Compose
2018-02-04 17:27:32 +03:00
If you do not wish to use Compose, you may still run this image using plain
2018-02-04 18:18:40 +03:00
Docker commands. Note that the following is just a guideline and you may need
to add parameters to the docker run command to account for the network situation
with your postgres database.
2017-09-28 13:12:47 +03:00
```
docker run \
-d \
--name synapse \
2018-02-04 17:27:32 +03:00
-v ${DATA_PATH}:/data \
-e SYNAPSE_SERVER_NAME=my.matrix.host \
2018-02-08 23:55:35 +03:00
-e SYNAPSE_REPORT_STATS=yes \
docker.io/matrixdotorg/synapse:latest
2017-09-28 13:12:47 +03:00
```
2018-02-04 17:27:32 +03:00
## Volumes
2018-02-04 18:18:40 +03:00
The image expects a single volume, located at ``/data``, that will hold:
2018-02-04 17:27:32 +03:00
* temporary files during uploads;
2018-02-06 00:12:50 +03:00
* uploaded media and thumbnails;
2018-02-06 01:13:27 +03:00
* the SQLite database if you do not configure postgres;
* the appservices configuration.
2018-02-08 21:48:53 +03:00
You are free to use separate volumes depending on storage endpoints at your
disposal. For instance, ``/data/media`` coud be stored on a large but low
performance hdd storage while other files could be stored on high performance
endpoints.
2018-02-06 01:13:27 +03:00
In order to setup an application service, simply create an ``appservices``
directory in the data volume and write the application service Yaml
configuration file there. Multiple application services are supported.
2018-02-04 17:27:32 +03:00
## Environment
2018-02-04 18:18:40 +03:00
Unless you specify a custom path for the configuration file, a very generic
2018-02-04 17:27:32 +03:00
file will be generated, based on the following environment settings.
These are a good starting point for setting up your own deployment.
2018-02-04 18:18:40 +03:00
Global settings:
* ``UID``, the user id Synapse will run as [default 991]
* ``GID``, the group id Synapse will run as [default 991]
2018-02-08 21:46:11 +03:00
* ``SYNAPSE_CONFIG_PATH``, path to a custom config file
2018-02-04 18:18:40 +03:00
2018-02-08 21:46:11 +03:00
If ``SYNAPSE_CONFIG_PATH`` is set, you should generate a configuration file
then customize it manually. No other environment variable is required.
Otherwise, a dynamic configuration file will be used. The following environment
variables are available for configuration:
2018-02-04 17:27:32 +03:00
* ``SYNAPSE_SERVER_NAME`` (mandatory), the current server public hostname.
2018-02-08 22:41:41 +03:00
* ``SYNAPSE_REPORT_STATS``, (mandatory, ``yes`` or ``no``), enable anonymous
2018-02-08 21:46:11 +03:00
statistics reporting back to the Matrix project which helps us to get funding.
2018-02-04 17:27:32 +03:00
* ``SYNAPSE_NO_TLS``, set this variable to disable TLS in Synapse (use this if
you run your own TLS-capable reverse proxy).
* ``SYNAPSE_ENABLE_REGISTRATION``, set this variable to enable registration on
the Synapse instance.
* ``SYNAPSE_ALLOW_GUEST``, set this variable to allow guest joining this server.
* ``SYNAPSE_EVENT_CACHE_SIZE``, the event cache size [default `10K` ].
2018-02-06 00:10:03 +03:00
* ``SYNAPSE_CACHE_FACTOR``, the cache factor [default `0.5` ].
2018-02-05 23:28:15 +03:00
* ``SYNAPSE_RECAPTCHA_PUBLIC_KEY``, set this variable to the recaptcha public
2018-02-05 23:53:53 +03:00
key in order to enable recaptcha upon registration.
2018-02-05 23:28:15 +03:00
* ``SYNAPSE_RECAPTCHA_PRIVATE_KEY``, set this variable to the recaptcha private
2018-02-05 23:53:53 +03:00
key in order to enable recaptcha upon registration.
* ``SYNAPSE_TURN_URIS``, set this variable to the coma-separated list of TURN
uris to enable TURN for this homeserver.
* ``SYNAPSE_TURN_SECRET``, set this to the TURN shared secret if required.
2018-02-04 17:27:32 +03:00
2018-02-08 21:46:11 +03:00
Shared secrets, that will be initialized to random values if not set:
2018-02-04 17:27:32 +03:00
* ``SYNAPSE_REGISTRATION_SHARED_SECRET``, secret for registrering users if
registration is disable.
2018-05-16 12:01:03 +03:00
* ``SYNAPSE_MACAROON_SECRET_KEY`` secret for signing access tokens
to the server.
2018-02-04 17:27:32 +03:00
Database specific values (will use SQLite if not set):
2018-05-01 21:47:58 +03:00
* `POSTGRES_DB` - The database name for the synapse postgres database. [default: `synapse` ]
2018-02-04 17:27:32 +03:00
* `POSTGRES_HOST` - The host of the postgres database if you wish to use postgresql instead of sqlite3. [default: `db` which is useful when using a container on the same docker network in a compose file where the postgres service is called `db` ]
* `POSTGRES_PASSWORD` - The password for the synapse postgres database. **If this is set then postgres will be used instead of sqlite3.** [default: none] **NOTE** : You are highly encouraged to use postgresql! Please use the compose file to make it easier to deploy.
* `POSTGRES_USER` - The user for the synapse postgres database. [default: `matrix` ]
2018-02-08 22:53:12 +03:00
Mail server specific values (will not send emails if not set):
* ``SYNAPSE_SMTP_HOST``, hostname to the mail server.
* ``SYNAPSE_SMTP_PORT``, TCP port for accessing the mail server [default ``25``].
* ``SYNAPSE_SMTP_USER``, username for authenticating against the mail server if any.
* ``SYNAPSE_SMTP_PASSWORD``, password for authenticating against the mail server if any.