Traefik with Docker Networks

时间:2017-07-19 10:06:03

标签: docker traefik

我真的不知道如何在码头网络中使用traefik。

我试着跑#34; wekan"看板。如果我将端口绑定到主机,它可以很好地工作,所以它真的是通过traefik来解决它。这是我的docker-config:

version: '2'

services:

 wekandb:
   image: mongo:3.2.14
   container_name: wekan-db
   command: mongod --smallfiles --oplogSize 128
   networks:
     - wekan-tier
   expose:
     - 27017
   volumes:
     - wekan-db:/data/db
     - wekan-db-dump:/dump

 wekan:
   image: wekanteam/wekan:latest
   container_name: wekan-app
   networks:
     - wekan-tier
#    ports:
#      - 8081:80
   environment:
     - MONGO_URL=mongodb://wekandb:27017/wekan
     - ROOT_URL=https://wekan.domain.com
   depends_on:
     - wekandb
   labels:
     - "traefik.port=80"
     - "traefik.backend=wekan"
     - "traefik.frontend.rule=Host:wekan.domain.com"
     - "traefik.docker.network=wekan_wekan-tier"
volumes:
 wekan-db:
   driver: local
 wekan-db-dump:
   driver: local

networks:
 wekan-tier:
   driver: bridge

我似乎无法找到一种方法来访问该死的东西......我的回答将不胜感激,它不仅可以让我运行Wekan,还可以更新我使用链接的旧服务:链接而不是Docker Networks - 现在已弃用链接。

2 个答案:

答案 0 :(得分:2)

我相信你在这里有不止一个问题。

首先,在你的作品中你没有Traefik服务,没关系,Traefik将能够从这里的服务中看到容器,但Traefik将无法向其发送请求,因为Traefik服务和wekan服务不共享同一网络。

因此,要解决此问题,您需要为Traefik创建一个特定的网络,并将其设置在您的撰写文件中。

示例:

$ docker network create traefik-net
$ docker service --name traefik --network traefik-net .... traefik ....

其次,您需要定义Traefik将用于连接您的服务的网络,此网络必须与Traefik服务共享。

所以你的wekan服务必须是这样的:

 wekan:
   image: wekanteam/wekan:latest
   container_name: wekan-app
   networks:
     - wekan-tier
     - traefik-net
   environment:
     - MONGO_URL=mongodb://wekandb:27017/wekan
     - ROOT_URL=https://wekan.domain.com
   depends_on:
     - wekandb
   labels:
     - "traefik.port=80"
     - "traefik.backend=wekan"
     - "traefik.frontend.rule=Host:wekan.domain.com"
     - "traefik.docker.network=traefik-net"

答案 1 :(得分:0)

我已经修改了您的docker-compose文件以使其正常工作:

version: '3'

services:

  web:
    image: wekanteam/wekan:latest
    networks:
    - wekan-tier
    environment:
    - MONGO_URL=mongodb://wekandb:27017/wekan
    - ROOT_URL=https://wekan.domain.com
    labels:
    - "traefik.port=80"
    - "traefik.docker.network=wekan_wekan-tier"

  wekandb:
    image: mongo:3.2
    command: mongod --smallfiles --oplogSize 128
    networks:
    - wekan-tier
    expose:
    - 27017
    volumes:
    - wekan-db:/data/db
    - wekan-db-dump:/dump

  traefik:
    image: 'traefik:1.6'
    command: --web --docker --docker.watch --docker.domain=local --logLevel=DEBUG
    labels:
    - traefik.docker.network=wekan-tier
    - traefik.port=8080
    ports:
    - '80:80'
    - '8080:8080'
    volumes:
    - '/var/run/docker.sock:/var/run/docker.sock'
    networks:
    - wekan-tier

volumes:
  wekan-db:
    driver: local
  wekan-db-dump:
    driver: local

networks:
  wekan-tier:
    driver: bridge

现在使用以下命令启动容器:

$ docker-compose -p wekan up -d

要检查traefik是否正常运行,请转到http://localhost:8080/,如果遇到问题,请使用$ service apache2 stop停止apache服务器。另一方面,如果您可以看到traefik界面,则将以下行添加到您的/etc/hosts文件中:

127.0.0.1   web.wekan.local

现在转到http://web.wekan.local,您应该会看到Wekan登录页面:)