在aws

时间:2018-01-02 23:35:08

标签: amazon-web-services docker docker-compose docker-swarm traefik

我正试图在我的码头服务中使用traefik(尽管只有1个docker服务开始)我已经能够设置traefik然而它忽略了我在docker中包含的标签撰写文件。我正在AWS上使用docker swarm。

日志表明 "Filtering container without port and no traefik.port label service_myapp.3"

我使用docker service inspectdocker container inspect检查了服务和容器,并且标签已经存在。

traefik Web控制台显示一个泊坞窗选项卡,但其下没有任何内容。

这是我的traefik.toml

logLevel = "DEBUG"
traefikLogsFile = "/var/logs/traefik.log"

[entryPoints]
    [entryPoints.http]
    address = ":80"
[web]
address = ":8080"

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "docker.localhost"
watch = true
swarmmode = true
exposedbydefault = false

这是我的docker compose yml

version: "3.4"
configs:
  traefik:
    external:
      name: traefik
services:
  traefik:
    image: traefik:1.3.5
    configs:
      - source: traefik
        target: /etc/traefik/traefik.toml
        mode: 0400
    depends_on:
      - myapp
    volumes:
      - traefiklogs:/var/logs
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    networks:
      - public
      - private
    tty: true
    deploy:
      mode: global
      placement:
        constraints:
          - node.role == manager
  myapp:
    image: myapp
    deploy:
      endpoint_mode: vip
      replicas: 3
      restart_policy:
        condition: on-failure
    ports:
      - "4000:8080"
    networks:
      - public
      - private
    labels:
      traefik.frontend.rule: "Host:myapp.myapp.com"
      traefik.backend: "myapp"
      traefik.docker.network=: "public"
      traefik.enable: "true"
      traefik.port: "4000"
networks:
  public:
    driver_opts:
      encrypted: 1
  private:
    driver_opts:
      encrypted: 1
volumes:
  sqldata:
  traefiklogs:

1 个答案:

答案 0 :(得分:1)

使用swarmmode = true,您需要在服务上设置标签而不是容器。这是通过在deploy部分中定义标签来完成的:

version: "3.4"
configs:
  traefik:
    external:
      name: traefik
services:
  traefik:
    image: traefik:1.3.5
    configs:
      - source: traefik
        target: /etc/traefik/traefik.toml
        mode: 0400
    depends_on:
      - myapp
    volumes:
      - traefiklogs:/var/logs
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    networks:
      - public
      - private
    tty: true
    deploy:
      mode: global
      placement:
        constraints:
          - node.role == manager
  myapp:
    image: myapp
    deploy:
      endpoint_mode: vip
      replicas: 3
      restart_policy:
        condition: on-failure
      labels:
        traefik.frontend.rule: "Host:myapp.myapp.com"
        traefik.backend: "myapp"
        traefik.docker.network=: "public"
        traefik.enable: "true"
        traefik.port: "4000"
    ports:
      - "4000:8080"
    networks:
      - public
      - private
networks:
  public:
    driver_opts:
      encrypted: 1
  private:
    driver_opts:
      encrypted: 1
volumes:
  sqldata:
  traefiklogs: