diff --git a/README.md b/README.md index 5f36c51..7d11915 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ docker-compose logs -f Some services may require additional configuration. Check for additional `README.md` files or comments in the `docker-compose.yml` files or `.env.dist` templates. +## Using a database server on the host from the container + +You need to change your database configuration to be able to do that. Check +[this](_docs/access_database_on_host_from_docker.md) documentation. + ## Is it working? Not every stack is tested to fully work. diff --git a/_docs/access_database_on_host_from_docker.md b/_docs/access_database_on_host_from_docker.md new file mode 100644 index 0000000..af90f1c --- /dev/null +++ b/_docs/access_database_on_host_from_docker.md @@ -0,0 +1,37 @@ +# Using database on host machine from Docker + + +## Database configuration + +### PostgreSQL +You need to make PostgreSQL listen not only `localhost`, but also Docker's network interface. + +To do that you need to add host machine IP address in the Docker network (usually `172.17.0.1`) to the `postgresql.conf`: +```ini +# Listen local interface and also Docker's network +listen_addresses = 'localhost,172.17.0.1' +``` + +Then you need to allow apps inside Docker containers to authenticate. That could be done in the `pg_hba.conf`: +``` +# Docker network +host all all 172.17.0.0/12 md5 +``` + +Do not forget to restart your PostgreSQL server. For PostgreSQL 12 it could be usually done like that: + +```shell +systemctl restart postgresql@12-main.service +``` + +### MySQL / MariaDB + +TBW + +## Application configuration inside Docker + +Stacks which allow to use external database back-end should also map `host.docker.internal` to the host machine +address inside Docker's default network. + +So to connect to the database from the application inside the container you should use `host.docker.internal` as the +database host/address. diff --git a/synapse/README.md b/synapse/README.md index 25ccd4a..fc35d89 100644 --- a/synapse/README.md +++ b/synapse/README.md @@ -10,7 +10,10 @@ docker-compose run synapse generate After that you can edit `./data/homeserver.yaml` according to your needs. -If you want to use full-fledged PostgreSQL instead of SQLite, you can check [this documentation](https://github.com/matrix-org/synapse/blob/master/docs/postgres.md). +If you want to use full-fledged PostgreSQL instead of SQLite, you can check +[this documentation](https://github.com/matrix-org/synapse/blob/master/docs/postgres.md). + +To use PostgreSQL running on the host machine, use [this](../_docs/access_database_on_host_from_docker.md) configuration. # Running the server diff --git a/synapse/docker-compose.yml b/synapse/docker-compose.yml index 5f694ab..f73ff4e 100644 --- a/synapse/docker-compose.yml +++ b/synapse/docker-compose.yml @@ -1,13 +1,22 @@ version: '3.7' +networks: + # You need to create this network manually first! + synapse: + external: true + services: synapse: # https://hub.docker.com/r/matrixdotorg/synapse # https://github.com/matrix-org/synapse/tree/master/docker image: "matrixdotorg/synapse:${IMAGE_VERSION:-latest}" container_name: synapse - # This way we'll be able to access PostgreSQL on local machine using 'localhost' when it's listening only locally. - network_mode: host + hostname: synapse + extra_hosts: + - 'host.docker.internal:host-gateway' + networks: + - default + - synapse ports: - "${INTERFACE_EXT:-127.0.0.1}:${HTTP_PORT_EXT:-8008}:${HTTP_PORT_INT:-8008}/tcp" volumes: