【问题标题】:Where are Traefik logs?Traefik 日志在哪里?
【发布时间】:2019-07-13 12:48:50
【问题描述】:

您是否知道 Traefik 日志的位置?我阅读了有关 Traefik 的文档,它说它会输出到标准输出,但是当我使用 docker-compose up -d 启动 docker 容器时,在我尝试域名并拉出多个链接的 docker 容器后,标准输出中没有显示任何内容。

我也尝试指定这些:

[traefikLog]
  filePath = "./traefik.log" #<--Tried this but It doesn't work, file empty and permissions set to 777

[accessLog]
  filePath = "./access.log" #<--Tried this but doesn't work, file empty and permissions set to 777

我很困惑,我错过了什么吗?还是 Traefik 应该这么安静?

当我运行它时,我看到的就是这些,之后什么都没有。

# docker-compose up
Creating traefik ... done
Attaching to traefik

附上我的配置。谢谢。

traefik/traefik.toml:

logLevel = "DEBUG"
defaultEntryPoints = ["http","https"]

[api]
  address = ":8080"

[traefikLog]
  filePath = "./traefik.log" #<--Tried this but It doesn't work

[accessLog]
  filePath = "./access.log" #<--Tried this but doesn't work

[entryPoints]
  [entryPoints.http]
    #redirect ALL http traffic to https 443
    address = ":80"
    [entryPoints.http.redirect]
      entryPoint = "https"
  [entryPoints.https]
    address = ":443"
    [entryPoints.https.tls]

#Let's encrypt setup
[acme]
  email = "email@email.com"
  storage = "acme.json"
  entryPoint = "https"
  acmeLogging = true
  #When new host is created, request certificate.
  onHostRule = true
  onDemand = false
  [acme.httpChallenge]
    entryPoint = "http"

#Watch Docker, when new containers are created with label create mapping.
[docker]
  endpoint = "unix:///var/run/docker.sock"
  domain = "exampledomain.net"
  watch = true
  exposedbydefault = false

docker-compose.yml:

version: '3'
services:
  traefik:
    hostname: traefik
    domainname: exampledomain.net
    image: traefik:alpine
    command: --api --docker
    container_name: traefik
    networks:
      - nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "./traefik/traefik.toml:/traefik.toml"
      - "./traefik/acme.json:/acme.json"
    labels:
      - "traefik.enable=true"
      - "traefik.port=8080"
      - "traefik.frontend.rule=Host:monitor.exampledomain.net"
      - "traefik.docker.network=nginx-proxy"

networks:
  nginx-proxy:
    external:
      name: nginx-proxy

【问题讨论】:

    标签: docker traefik


    【解决方案1】:

    如果您运行docker-compose up -d,要查看标准输出事件中的日志:

    docker-compose log -f
    

    https://docs.docker.com/compose/reference/logs/

    仅供参考,路径 ./traefik.log 在 Traefik 容器内。

    [traefikLog]
      filePath = "./traefik.log" 
    

    通过您的文件(没有[traefikLog] 部分),我看到了日志。


    但是,您的配置存在一些问题:

    version: '3'
    services:
      traefik:
        hostname: traefik
        domainname: exampledomain.net
        image: traefik:v1.7.9-alpine
        # command: --api --docker # <-- don't define the same configuration with CLI and TOML https://docs.traefik.io/basics/#static-traefik-configuration
        container_name: traefik
        networks:
          - nginx-proxy
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - "/var/run/docker.sock:/var/run/docker.sock"
          - "./traefik/traefik.toml:/traefik.toml"
          - "./traefik/acme.json:/acme.json"
        labels:
          - "traefik.enable=true"
          - "traefik.port=8080"
          - "traefik.frontend.rule=Host:monitor.exampledomain.net"
          - "traefik.docker.network=nginx-proxy"
    
    networks:
      nginx-proxy:
        external:
          name: nginx-proxy
    
    logLevel = "DEBUG"
    defaultEntryPoints = ["http","https"]
    
    [api]
      # address = ":8080" <- this options doesn't exist. https://docs.traefik.io/v1.7/configuration/api/
    
    # [traefikLog] # <-- remove because not needed
    #   filePath = "./traefik.log"
    
    # [accessLog] # <-- remove because not needed
    #   filePath = "./access.log"
    
    [entryPoints]
      [entryPoints.http]
        address = ":80"
        [entryPoints.http.redirect]
          entryPoint = "https"
      [entryPoints.https]
        address = ":443"
        [entryPoints.https.tls]
    
    # Let's encrypt setup
    [acme]
      email = "email@email.com"
      storage = "acme.json"
      entryPoint = "https"
      acmeLogging = true
      onHostRule = true
      onDemand = false
      [acme.httpChallenge]
        entryPoint = "http"
    
    [docker]
      endpoint = "unix:///var/run/docker.sock"
      domain = "exampledomain.net"
      # watch = true # <---- useful only for swarm
      exposedbydefault = false
    

    【讨论】:

    • 这就是我所看到的一切..# docker-compose logs -f 附加到 traefik
    • 你能不能尝试做一个简单的docker-compose up(没有-d)
    • 并删除部分[traefikLog]
    • 谢谢,删除命令行似乎会给我返回日志,但现在它不读取 traefik.toml 文件。或者它从来没有被阅读过。
    • 感谢“路径 ./traefik.log 在 Traefik 容器内。”
    【解决方案2】:

    我正在共享一个 docker-compose 文件,该文件将为访问日志和服务日志创建一个卷:

    "networks":
      "network":
        "external":
          "name": "appliance"
    "services":
      "container":
        "container_name": "traefik"
        "image": "traefik:1.7.4"
        "networks":
        - "network"
        "ports":
        - "80:80"
        - "443:443"
        - "8099:8099"
        "restart": "always"
        "volumes":
        - "/var/run/docker.sock:/var/run/docker.sock"
        - "{pwd}/traefik.toml:/traefik.toml"
        - "{pwd}/acme.json:/acme.json"
        - "logs:/var/log/traefik"
    "version": "3.4"
    "volumes":
      "logs":
        "name": "traefik_logs"
    

    在traefik.toml中添加日志位置如下:

    [accessLog]
    filePath = "/var/log/traefik/access.log"
    

    【讨论】:

      【解决方案3】:

      只需将[accessLog] 添加到您的traefik.toml 文件中即可。

      【讨论】:

        猜你喜欢
        • 2016-06-04
        • 1970-01-01
        • 1970-01-01
        • 2016-03-10
        • 2021-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多