带有Docker Stack的Traefik无法检测端口

时间:2018-07-01 15:25:19

标签: docker traefik

我创建了一个我想与Docker和Traeffik一起部署的网站。

当我手动部署服务时,所有内容都像一个超级按钮。

首先创建一个网络

docker network create --driver overlay traefik-net

接下来创建Traefik服务

docker service create \
    --name traefik \
    --constraint=node.role==manager \
    --publish 80:80 --publish 8080:8080 \
    --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
    --mount type=bind,source=$PWD/traefik.toml,target=/etc/traefik/traefik.toml \
    --network traefik-net \
    traefik \
    --docker \
    --docker.swarmMode \
    --docker.domain=traefik \
    --docker.watch \
    --api

最后,创建网站服务

docker service create \
    --name johanvergeer \
    --label traefik.port=4000 \
    --label traefik.frontend.rule='Host:johanvergeer.com' \
    --network traefik-net \
    registry.gitlab.com/johanvergeer/redgyro/site:latest

为进行配置,我创建了一个traefik.toml文件

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

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

但是当我停止服务并尝试使用Docker堆栈启动它们时,由于某种原因它将无法工作。

docker-compose文件

version: "3.6"
services:
  site:
    ports:
      - 4000:4000
    image: mywebsite:latest
    labels:
      - traefik.site.port=4000
      - traefik.enable=true
      - traefik.frontend.rule=Host:mydomain.com
    networks: 
      - traefik-net

  reverse-proxy:
    image: traefik # The official Traefik docker image
    ports:
      - "80:80"     # The HTTP port
      - "8080:8080" # The Web UI (enabled by --api)
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
      - $PWD/traefik.toml:/etc/traefik/traefik.toml
    deploy:
      labels:
        traefik.logLevel: 'DEBUG'
      placement:
        constraints:
          - node.role == manager
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure
    networks:
      - traefik-net

networks: 
  traefik-net:
    name: traefik-net

在traefik服务的日志中,我看到未使用traefik.site.port=4000标签。

此外,我还注意到了空的Docker配置:level=debug msg="Configuration received from provider docker: {}"

level=info msg="Using TOML configuration file /etc/traefik/traefik.toml"
level=info msg="Traefik version v1.6.4 built on 2018-06-15_03:12:50PM"
level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://docs.traefik.io/basics/#collected-data\n"
level=debug msg="Global configuration loaded {\"LifeCycle\":{\"RequestAcceptGraceTimeout\":0,\"GraceTimeOut\":10000000000},\"GraceTimeOut\":0,\"Debug\":false,\"CheckNewVersion\":true,\"SendAnonymousUsage\":false,\"AccessLogsFile\":\"\",\"AccessLog\":null,\"TraefikLogsFile\":\"\",\"TraefikLog\":null,\"Tracing\":null,\"LogLevel\":\"DEBUG\",\"EntryPoints\":{\"http\":{\"Address\":\":80\",\"TLS\":null,\"Redirect\":null,\"Auth\":null,\"WhitelistSourceRange\":null,\"WhiteList\":null,\"Compress\":false,\"ProxyProtocol\":null,\"ForwardedHeaders\":{\"Insecure\":true,\"TrustedIPs\":null}},\"traefik\":{\"Address\":\":8080\",\"TLS\":null,\"Redirect\":null,\"Auth\":null,\"WhitelistSourceRange\":null,\"WhiteList\":null,\"Compress\":false,\"ProxyProtocol\":null,\"ForwardedHeaders\":{\"Insecure\":true,\"TrustedIPs\":null}}},\"Cluster\":null,\"Constraints\":[],\"ACME\":null,\"DefaultEntryPoints\":[\"http\"],\"ProvidersThrottleDuration\":2000000000,\"MaxIdleConnsPerHost\":200,\"IdleTimeout\":0,\"InsecureSkipVerify\":false,\"RootCAs\":null,\"Retry\":null,\"HealthCheck\":{\"Interval\":30000000000},\"RespondingTimeouts\":null,\"ForwardingTimeouts\":null,\"AllowMinWeightZero\":false,\"Web\":null,\"Docker\":{\"Watch\":true,\"Filename\":\"\",\"Constraints\":null,\"Trace\":false,\"TemplateVersion\":2,\"DebugLogGeneratedTemplate\":false,\"Endpoint\":\"unix:///var/run/docker.sock\",\"Domain\":\"mydomain.com\",\"TLS\":null,\"ExposedByDefault\":true,\"UseBindPortIP\":true,\"SwarmMode\":true},\"File\":null,\"Marathon\":null,\"Consul\":null,\"ConsulCatalog\":null,\"Etcd\":null,\"Zookeeper\":null,\"Boltdb\":null,\"Kubernetes\":null,\"Mesos\":null,\"Eureka\":null,\"ECS\":null,\"Rancher\":null,\"DynamoDB\":null,\"ServiceFabric\":null,\"Rest\":null,\"API\":{\"EntryPoint\":\"traefik\",\"Dashboard\":true,\"Debug\":false,\"CurrentConfigurations\":null,\"Statistics\":null},\"Metrics\":null,\"Ping\":null}"
level=info msg="Preparing server traefik &{Address::8080 TLS:<nil> Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] WhiteList:<nil> Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc4206b06c0} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
level=info msg="Preparing server http &{Address::80 TLS:<nil> Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] WhiteList:<nil> Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc4206b06e0} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
level=info msg="Starting provider *docker.Provider {\"Watch\":true,\"Filename\":\"\",\"Constraints\":null,\"Trace\":false,\"TemplateVersion\":2,\"DebugLogGeneratedTemplate\":false,\"Endpoint\":\"unix:///var/run/docker.sock\",\"Domain\":\"mydomain.com\",\"TLS\":null,\"ExposedByDefault\":true,\"UseBindPortIP\":true,\"SwarmMode\":true}"
level=info msg="Starting server on :8080"
level=info msg="Starting server on :80"
level=debug msg="Provider connection established with docker 18.05.0-ce (API 1.37)"
level=debug msg="Configuration received from provider docker: {}"
level=info msg="Server configuration reloaded on :80"
level=info msg="Server configuration reloaded on :8080"
level=debug msg="originLabelsmap[traefik.logLevel:DEBUG com.docker.stack.image:traefik com.docker.stack.namespace:traefik_stack]"
level=debug msg="allLabelsmap[:map[traefik.logLevel:DEBUG]]"
level=debug msg="Filtering container without port, traefik_stack_reverse-proxy.1: port label is missing, please use traefik.port as default value or define port label for all segments ('traefik.<segment_name>.port')"
level=debug msg="originLabelsmap[com.docker.stack.image:mywebsite:latest com.docker.stack.namespace:traefik_stack]"
level=debug msg="allLabelsmap[:map[]]"
level=debug msg="Filtering container without port, traefik_stack_site.1: port label is missing, please use traefik.port as default value or define port label for all segments ('traefik.<segment_name>.port')"
level=debug msg="Configuration received from provider docker: {}"
level=info msg="Skipping same configuration for provider docker"
level=debug msg="originLabelsmap[com.docker.stack.namespace:traefik_stack traefik.logLevel:DEBUG com.docker.stack.image:traefik]"
level=debug msg="allLabelsmap[:map[traefik.logLevel:DEBUG]]"
level=debug msg="Filtering container without port, traefik_stack_reverse-proxy.1: port label is missing, please use traefik.port as default value or define port label for all segments ('traefik.<segment_name>.port')"
level=debug msg="originLabelsmap[com.docker.stack.namespace:traefik_stack com.docker.stack.image:mywebsite:latest]"
level=debug msg="allLabelsmap[:map[]]"
level=debug msg="Filtering container without port, traefik_stack_site.1: port label is missing, please use traefik.port as default value or define port label for all segments ('traefik.<segment_name>.port')"
level=debug msg="Configuration received from provider docker: {}"
level=info msg="Skipping same configuration for provider docker"

到现在为止,这已经花了一整天了,因为可能是非常简单的设置,我错过了某个地方。 有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:3)

使用配置为群模式的traefik时,需要在服务而非容器上设置标签。您可以通过将标签移动到撰写文件中的deploy块内来实现:

services:
  site:
    ports:
      - 4000:4000
    image: mywebsite:latest
    deploy:
      labels:
        - traefik.site.port=4000
        - traefik.enable=true
        - traefik.frontend.rule=Host:mydomain.com
    networks: 
      - traefik-net