dendrite icon indicating copy to clipboard operation
dendrite copied to clipboard

Explanation on how to set this server up with a Single Docker Compose File

Open Ryu945 opened this issue 5 years ago • 12 comments

I am trying to figure out how to setup a single docker compose file to setup everything needed for the Dendrite server. I see in the guide it mentions run two separate docker compose files but I don't even see how it communicates as no ports are published.

Ryu945 avatar Oct 26 '20 19:10 Ryu945

Hey,

An example of mine using traefik:

  matrix:
    container_name: matrix
    image: matrixdotorg/dendrite-monolith:latest
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.matrix.rule=Host(`matrix.wounn.xyz`) || PathPrefix(`/_matrix`)"
      - "traefik.http.routers.matrix.entrypoints=websecure"
      - "traefik.http.routers.matrix.tls.certresolver=myresolver"
      - "traefik.http.routers.matrix.middlewares=corsMatrix@file"
      # - "traefik.http.services.matrix.loadbalancer.server.port=8008"
      # - "traefik.http.services.matrix.loadbalancer.server.port=8008"
      # - "traefik.port=8008"
    command: [
      "--tls-cert=server.crt",
      "--tls-key=server.key"
    ]
    volumes:
      - ./matrix:/etc/dendrite
    ports: 
      - 8008:8008
    networks:
      - traefik
      - db
    depends_on:
      - traefik
      - postgres
    restart: unless-stopped

I can make a PR to expose the default ports but it's not mandatory to have them exposed, you can attach the ports anyway. Didn't need of 8448 because traefik is dealing with SSL.

HelderFSFerreira avatar Oct 26 '20 21:10 HelderFSFerreira

Doesn't this mean that all clients connecting to your server have to use HTTP only since the clients know to only use HTTP on 8008 and HTTPS on 8448.

Ryu945 avatar Oct 31 '20 16:10 Ryu945

The SSL is handled on traefik and all the clients are using https. This means that all the traefik between traefik and dendrite is http but they are on the same machine.

HelderFSFerreira avatar Nov 01 '20 00:11 HelderFSFerreira

I am talking about the traffic between the client and the traefik server. I thought the server only connect to clients over SSL on 8448 and non ssl over 8008. Behind the proxy is another story. I am just talking about between the client and the reverse proxy. I thought the way it would normally work is the client talks with https up to port 8448. The reverse proxy terminates the SSL at that point and communicates with Dendrite over port 8008 the rest of the way.

Are you saying the client is able to communicate with the server using HTTPS to port 8008? Then it terminates SSL and continues on port 8008 on HTTP to the Dendrite server?

Ryu945 avatar Nov 02 '20 20:11 Ryu945

HTTPS (port 443) -> traefik (handles SSL) -> dendrite (Port 8008)

HelderFSFerreira avatar Nov 03 '20 09:11 HelderFSFerreira

Oh, clients use 443? I didn't see that in the guide when I was reading through it at all. I wouldn't have guessed that.

Ryu945 avatar Nov 03 '20 19:11 Ryu945

That's because they are using a reverse proxy like Apache or nginx which will terminate TLS and forward the now unencrypted traffic to :8008. It's not a dendrite specific thing.

kegsay avatar Nov 09 '20 18:11 kegsay

One who does not know how the service is setup could assume that its ports of operation were intentionally picked to not be 80 or 443.

Ryu945 avatar Nov 14 '20 21:11 Ryu945

Indeed, the example of using multiple compose files is a bit strange. The whole purpose of Docker compose is to use a single file, eg. containing postgres with a dependency to dendrite (via depends_on:)

melroy89 avatar Jan 12 '21 16:01 melroy89

This is my docker-compose.yml. Maybe it helps somehow?

version: "3.4"
services:
  monolith:
    hostname: monolith
    image: matrixdotorg/dendrite-monolith:latest
    restart: always
    command: [
      "--tls-cert=server.crt",
      "--tls-key=server.key"
    ]
    ports:
      - 8008:8008
      - 8448:8448
    volumes:
      - ./config:/etc/dendrite
    networks:
      - internal
    depends_on:
      - postgres

  # PostgreSQL is needed for both polylith and monolith modes.
  postgres:
    hostname: postgres
    image: postgres:11
    restart: always
    volumes:
      - ./postgres/create_db.sh:/docker-entrypoint-initdb.d/20-create_db.sh
    # To persist your PostgreSQL databases outside of the Docker image, to 
    # prevent data loss, you will need to add something like this:
    # - /MY/LOCAL/PATH/data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: itsasecret
      POSTGRES_USER: dendrite
    networks:
      - internal
      
networks:
  internal:
    attachable: true

dassystem avatar Jan 28 '21 18:01 dassystem

I'll look to add a docker compose example for monolith (which is the recommended way of running Dendrite) sometime soon.

kegsay avatar Nov 03 '21 15:11 kegsay

Something I haven't wrapped my head around and it doesn't seem to be in the docs. Do I need to set tls-cert and tls-key on the monolith if I'm throwing traefik or haproxy in front?

dwarf-king-hreidmar avatar Jul 24 '22 19:07 dwarf-king-hreidmar

@HelderFSFerreira could you please share the docker-compose.yml including content of corsMatrix@file? This would be sooo helpful. I am going to setup the same but in swarm.

plague-doctor avatar Oct 22 '22 07:10 plague-doctor

@plague-doctor there you have it:

http:
  middlewares:
    corsMatrix:
      headers:
        accessControlAllowMethods:
          - GET
          - POST
          - PUT
          - DELETE
          - OPTIONS
        accessControlAllowOriginList:
          - "*"
        accessControlAllowHeaders:
          - Origin
          - X-Requested-With
          - Content-Type
          - Accept
          - Authorization
        accessControlMaxAge: 100
        addVaryHeader: true

HelderFSFerreira avatar Nov 15 '22 11:11 HelderFSFerreira

We don't support docker-compose as a maintained runtime configuration. We will however support Helm charts, which are kinda like docker-compose in some ways.

kegsay avatar Dec 05 '22 17:12 kegsay