用一个docker-compose.yml启动两个wiki js容器,通过traefik分离数据库(postgres)

Start two wikijs containers with one docker-compose.yml and seperate database (postgres) through traefik

我正在尝试通过 traefik 启动两个具有不同数据库的 wikijs 容器。我在启动容器时没有问题。我可以在一个子域上启动 traefik,我什至可以在不同的子域上启动两个 wiki。我的问题如下:每次启动 wikijs 容器时,我总是以某种方式使用相同的数据库,但我不知道如何更改它。

我的目的是,我有一些客户希望为他们的文档创建一个单独的 wiki。所以我想启动尽可能多的 wikijs 容器,但最好通过一个 docker-compose.yml 文件。

谁能告诉我,我做错了什么?谢谢=)

这是我的 traefik.toml 文件:

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.http]
    address = ":80"
      [entryPoints.http.redirect]
        entryPoint = "https"
  [entryPoints.https]
    address = ":443"
      [entryPoints.https.tls]
  [entryPoints.dashboard]
    address = ":8080"
    [entryPoints.dashboard.auth]
      [entryPoints.dashboard.auth.basic]
        users = ["admin:$apr1$Ld55R9Cl$/8W5BCc.J/Qtg9Xtpk4lq0"]

[api]
entrypoint="dashboard"

[acme]
email = "email@domain.com" 
storage = "acme.json"
entryPoint = "https"
onHostRule = true
  [acme.httpChallenge]

这是我的 docker-compose.yml 文件:

services:

  db:
    image: postgres:11-alpine
    networks:
      - internal
    labels:
      - "traefik.enable=false"
    environment:
      POSTGRES_DB: wiki1
      POSTGRES_PASSWORD: wikijsrocks
      POSTGRES_USER: wikijs

    logging:
      driver: "none"
    restart: unless-stopped
    volumes:
      - db-data:/var/lib/postgresql/data
  db1:
    image: postgres:11-alpine
    networks:
      - internal
    labels:
      - "traefik.enable=false"
    environment:
      POSTGRES_DB: wiki2
      POSTGRES_PASSWORD: wikijsrocks
      POSTGRES_USER: wikijs

    logging:
      driver: "none"
    restart: unless-stopped
    volumes:
      - db-data1:/var/lib/postgresql/data

  wiki1:
    image: requarks/wiki:2
    networks:
      - internal
      - web
    labels:
      - "traefik.enable=true"
      - "traefik.backend=wiki1"
      - "traefik.docker.network=web"
      - "traefik.frontend.rule=Host:domain.com"
      - "traefik.http.services.wiki.loadbalancer.server.port=3000"

    depends_on:
      - db
    environment:
      DB_TYPE: postgres
      DB_HOST: db
      DB_PORT: 5432
      DB_USER: wikijs
      DB_PASS: wikijsrocks
      DB_NAME: wiki
    restart: unless-stopped

  wiki2:
    image: requarks/wiki:2
    networks:
      - internal
      - web
    labels:
      - "traefik.enable=true"
      - "traefik.backend=wiki2"
      - "traefik.docker.network=web"
 - "traefik.frontend.rule=Host:domain.com"                                                                                                                                                                                        - "traefik.http.services.wiki.loadbalancer.server.port=3000"

    depends_on:
      - db1
    environment:
      DB_TYPE: postgres
      DB_HOST: db1
      DB_PORT: 5432
      DB_USER: wikijs
      DB_PASS: wikijsrocks
      DB_NAME: wikispiral
    restart: unless-stopped

  adminer:
    image: adminer:4.6.3-standalone
    labels:
      - traefik.backend=adminer
      - traefik.frontend.rule=Host:domain.com
      - traefik.docker.network=web
      - traefik.port=8080
    networks:
      - internal
      - web
    depends_on:
      - db
      - db1
volumes:
  db-data:
  db-data1:
networks:
  web:
    external: true
internal:
    external: false

两个数据库在同一网络上:

networks:
      - internal

并在同一端口上侦听:

DB_PORT: 5432

所以将每个数据库放在它自己的网络中,并将该网络添加到 wiki 服务,或者更改其中一个正在侦听的端口。