一台主机上带有Traefik的两个Docker容器

时间:2019-05-11 16:47:32

标签: docker docker-compose traefik docker-container

我正在尝试在树莓派上设置服务器,以使用traefik作为反向代理运行Nextcloud和Firefly III。我正在使用docker-compose,Portainer与https(测试代码中已包含)一起正常工作,但我根本无法运行Nextcloud或Firefly。当我使用Firefly的官方文档时,我可以运行它,而当我本身使用NextcloudPi时,我也可以运行它,但是我不能同时使用它们。 FF给出了403禁止访问“您无权访问此服务器上的/”。错误,而Nextcloud给出“错误的网关”错误。我很感激,因为我已经阅读了尽可能多的网站,而我无事可做。

这是我的docker-compose.yml:

version: "3.2"

services:
  # Reverse Proxy and Let's Encrypt
  traefik:
    container_name: traefik
    image: traefik:alpine
    restart: always
    networks:
      - srv
      - firefly_iii_net
      - proxy-tier
    ports:
      - 80:80
      - 443:443
    volumes:
      - /opt/traefik/traefik.toml:/traefik.toml
      - /var/run/docker.sock:/var/run/docker.sock
      - /opt/traefik/acme.json:/acme.json

  # Portainer
  portainer:
    container_name: portainer
    image: portainer/portainer
    restart: always
    networks:
      - srv
    ports:
      - "9000:9000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /opt/portainer:/data
    labels:
      - traefik.enable=true
      - "traefik.frontend.rule=Host:port.skdjfgsl.club"

  db:
    image: postgres:alpine
    restart: always
    volumes:
      - db:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=
      - POSTGRES_DB=nextcloud
      - POSTGRES_USER=nextcloud

  app:
    image: nextcloud:fpm-alpine
    restart: always
    volumes:
      - nextcloud:/var/www/html
    environment:
      - POSTGRES_HOST=db
      - POSTGRES_PASSWORD=
      - POSTGRES_DB=nextcloud
      - POSTGRES_USER=nextcloud
    depends_on:
      - db
    networks:
      - proxy-tier
    expose:
      - 80
      - 443
    labels:
      - traefik.enable=true
      - "traefik.frontend.rule=Host:nc.skdjfgsl.club"

  firefly_iii_app: 
    environment: 
      - FF_DB_HOST=firefly_iii_db
      - FF_DB_NAME=firefly
      - FF_DB_USER=firefly
      - FF_DB_PASSWORD=firefly
      - FF_APP_KEY=S0m3R@nd0mStr1ngOf32Ch@rsEx@ctly
      - FF_APP_ENV=local
      - FF_DB_CONNECTION=pgsql
      - TZ=Europe/Amsterdam
      - APP_LOG_LEVEL=debug
      - TRUSTED_PROXIES=**
    image: jc5x/firefly-iii
    links: 
      - firefly_iii_db
    networks: 
      - firefly_iii_net
    volumes: 
      - 
        source: firefly_iii_export
        target: /var/www/firefly-iii/storage/export
        type: volume
      - 
        source: firefly_iii_upload
        target: /var/www/firefly-iii/storage/upload
        type: volume
    expose:
      - 80
      - 443
    labels:
      - traefik.enable=true
      - "traefik.frontend.rule=Host:ff.skdjfgsl.club"
      - traefik.port=443

  firefly_iii_db: 
    environment: 
      - POSTGRES_PASSWORD=firefly
      - POSTGRES_USER=firefly
    image: "postgres:10"
    networks: 
      - firefly_iii_net
    volumes: 
      - "firefly_iii_db:/var/lib/postgresql/data"

networks:
  srv:
  firefly_iii_net: 
    driver: bridge
  proxy-tier:

volumes:
  db:
  nextcloud:
  firefly_iii_db: ~
  firefly_iii_export: ~
  firefly_iii_upload: ~

这是我的traefik.toml:

defaultEntryPoints = ["http", "https"]

logLevel = "DEBUG"

[entryPoints]
  [entryPoints.http]
    address = ":80"
      [entryPoints.http.redirect]
        entryPoint = "https"
  [entryPoints.https]
    address = ":443"
      [entryPoints.https.tls]

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "mydomain.com"
exposedByDefault = false
watch = true

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

1 个答案:

答案 0 :(得分:0)

要转到端口443(https),您需要调整traefik用来与带有以下标签的容器通信的协议:

- traefik.protocol=https

错误的网关可能意味着traefik试图连接到错误的端口,错误的IP或traefik,并且容器未部署到公共网络。您可以通过指定端口和网络名称来修复前两个问题:

- traefik.port=80
- traefik.docker.network=project_proxy-tier

项目是您的撰写项目的名称(使用docker network ls查看网络的外部名称)。