6

我建立了一个安装了 docker 和 docker-compose 的 debian 服务器。

我在我的 sudo 用户的家中创建了一个具有以下层次结构的文件夹:

~/docker-project
      - docker-compose.yml
      - /traefik/traefik.toml

我做了docker-compose up -d一切都开始了,我可以访问具有工作 ssl 证书的 traefik.mydomain.com,其他子域也是如此。但是,如果我去我的任何子域访问我的 dockerized Web 服务,我会在我的浏览器中收到一条错误的网关消息。如果我转到我的服务器 IP 地址并放置正确的端口,我会看到我的网络服务运行良好。

所以我认为我在配置 docker / traefik 关系时犯了一个错误,但我找不到在哪里。

这是我的traefik.toml

defaultEntryPoints = ["http", "https"]

################################################################
# Web configuration backend
################################################################
[web]
address = ":8080"
[web.auth.basic]
# User: user | Password: password
users = ["user:hashedpassword"]

################################################################
# Entry-points configuration
################################################################
[entryPoints]
  [entryPoints.http]
    address = ":80"
    [entryPoints.http.redirect]
      entryPoint = "https"
  [entryPoints.https]
    address = ":443"
    [entryPoints.https.tls]

################################################################
# Docker configuration backend
################################################################
[docker]
domain = "mydomain.com"
watch = true
exposedbydefault = false

################################################################
# Let's encrypt
################################################################
[acme]
email = "my-email@mail.com"
storageFile = "/etc/traefik/acme.json"
onDemand = false
onHostRule = true
entryPoint = "https"

这是我的docker-compose.yml

version: '2'
services:

  traefik:
    restart: always
    image: traefik
    container_name: traefik
    ports:
      - '80:80'
      - '443:443'
      - '8080:8080'
    labels:
      - 'traefik.enable=true'
      - 'traefik.docker.network=dockerplatform_default'
      - 'traefik.port=8080'
      - 'traefik.frontend.rule=Host:traefik.mydomain.com'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik:/etc/traefik

  plex:
    image: linuxserver/plex
    container_name: plex
    environment:
      - VERSION=latest
      - PUID=1000
      - PGID=1000
      - TZ=TZ
    labels:
      - 'traefik.enable=true'
      - 'traefik.docker.network=dockerplatform_default'
      - 'traefik.port=9001'
      - 'traefik.frontend.rule=Host:plex.mydomain.com' 
    ports:
      - '9001:32400'
    volumes:
      - 'plex:/config'
      - 'plex_transcode:/transcode'
      - '/home/downloader/Downloads:/data/'

  plexpy:
    image: linuxserver/plexpy
    container_name: plexpy
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=TZ
    labels:
      - 'traefik.enable=true'
      - 'traefik.docker.network=dockerplatform_default'
      - 'traefik.port=9002'
      - 'traefik.frontend.rule=Host:plexpy.mydomain.com' 
    ports:
      - '9002:8181'
    volumes:
      - 'plexpy:/config'

  transmission:
    image: linuxserver/transmission
    container_name: transmission
    environment:
      - PGID=1000
      - PUID=1000
      - TZ=TZ
    labels:
      - 'traefik.enable=true'
      - 'traefik.docker.network=dockerplatform_default'
      - 'traefik.port=9003'
      - 'traefik.frontend.rule=Host:bt.mydomain.com' 
    ports:
      - '9003:9091'
      - '51413:51413'
      - '51413:51413/udp'
    volumes:
      - 'transmission:/config'
      - '/home/downloader/Downloads:/downloads'
      - '/home/downloader/Downloads:/watch'

volumes:
  plex:
    driver: local
  plex_transcode:
    driver: local
  plexpy:
    driver: local
  transmission:
    driver: local

感谢您的帮助。

4

2 回答 2

8

因此,由于了不起的 traefik slack 频道,我设法得到了答案!

所以我的容器都在同一个 docker 网络中,包括我的 traefik 容器。

问题是我将所有容器端口映射为可从主机访问。

相反,我应该只将 traefik 端口映射到主机并公开我的 Web 服务容器的端口,以便 traefik 可以在它们都在的 docker 网络中监听它们。

更改: -添加公开 -更改traefik.port

我只需要在我的 docker-compose.yml 中进行这些更改:

version: '2'
services:

  traefik:
    restart: always
    image: traefik
    container_name: traefik
    ports:
      - '80:80'
      - '443:443'
      - '8080:8080'
    labels:
      - 'traefik.enable=true'
      - 'traefik.docker.network=dockerplatform_default'
      - 'traefik.port=8080'
      - 'traefik.frontend.rule=Host:traefik.mydomain.com'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik:/etc/traefik

  plex:
    image: linuxserver/plex
    container_name: plex
    environment:
      - VERSION=latest
      - PUID=1000
      - PGID=1000
      - TZ=TZ
    labels:
      - 'traefik.enable=true'
      - 'traefik.docker.network=dockerplatform_default'
      - 'traefik.port=32400'
      - 'traefik.frontend.rule=Host:plex.mydomain.com' 
    #ports:
    #  - '9001:32400'
    expose:
      - 32400
    volumes:
      - 'plex:/config'
      - 'plex_transcode:/transcode'
      - '/home/downloader/Downloads:/data/'

  plexpy:
    image: linuxserver/plexpy
    container_name: plexpy
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=TZ
    labels:
      - 'traefik.enable=true'
      - 'traefik.docker.network=dockerplatform_default'
      - 'traefik.port=8181'
      - 'traefik.frontend.rule=Host:plexpy.mydomain.com' 
    #ports:
    #  - '9002:8181'
    expose:
      - 8181
    volumes:
      - 'plexpy:/config'

  transmission:
    image: linuxserver/transmission
    container_name: transmission
    environment:
      - PGID=1000
      - PUID=1000
      - TZ=TZ
    labels:
      - 'traefik.enable=true'
      - 'traefik.docker.network=dockerplatform_default'
      - 'traefik.port=9091'
      - 'traefik.frontend.rule=Host:bt.mydomain.com' 
    #ports:
    #  - '9003:9091'
    #  - '51413:51413'
    #  - '51413:51413/udp'
    expose:
      - 9091
      - 51413
    volumes:
      - 'transmission:/config'
      - '/home/downloader/Downloads:/downloads'
      - '/home/downloader/Downloads:/watch'

volumes:
  plex:
    driver: local
  plex_transcode:
    driver: local
  plexpy:
    driver: local
  transmission:
    driver: local
于 2017-09-21T14:32:30.067 回答
0

由于 Traefik v2 现在已经发布,这个问题值得更新:

  • expose不再需要端口定义。
  • port该容器的映射定义也不是。
  • 唯一需要的是,容器中的某些东西正在监听。

注意:如果您为例如 Nginx 容器定义,请添加标签 - 'traefik.port=9091' 但还要添加侦听端口的服务器 conf 9091

于 2020-12-22T09:04:08.160 回答