首页 文章

无法通过docker-compose.yml中的“标签”设置Traefik

提问于
浏览
2

Traefik完全忽略了“标签”配置 .

Traefik's main documentation page之后,我们可以简单地做到:

#docker-compose.yml

version: '3'

services:

  traefik:
    image: traefik # The official Traefik docker image
    command: --api --docker # Enables the web UI and tells Træfik to listen to docker
    ports:
      - "80:80"     # The HTTP port
      - "8080:8080" # The Web UI (enabled by --api)
    volumes:
      - ./docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events

  whoami:
      image: emilevauge/whoami # A container that exposes an API to show its IP address
      labels:
        - "traefik.frontend.rule=Host:whoami.docker.localhost"

然后,运行docker-compose就足够了(没有traefik.toml文件):

docker-compose up -d

结果在预期中:

Starting test_traefik_1 ... done
Starting test_whoami_1  ... done

但不幸的是,Traefik的仪表板没有显示任何内容:

没有找到提供者

我试图做什么:

  • 还要使用另一种labels表示法:

标签:
traefik.backend:“whoami”
traefik.frontend.rule:“主持人:whoami.docker.localhost”

  • 要关注this guide .

  • 删除"version: '3'",并将其更改为"version: '3.3'" .

  • 在Powershell上运行 $env:DOCKER_HOST="npipe:////./pipe/docker_engine"$env:DOCKER_HOST="tcp://localhost:2375" .

  • 设置npipe而不是unix socket:

卷:

  • 类型:npipe
    来源:./管
    target:/ pipe / docker_engine

什么都行不通 .

现在,我可以在仪表板中查看内容的唯一方法是将此行添加到Traefik卷:“ - ./traefik.toml:/traefik.toml”,同时使用[file]配置创建“traefik.toml”文件 . 我不想拥有这个文件 . 我想把控件放在docker-compose.yml里面的“标签”里面 .

知道我应该何时使用traefik.toml文件,而不是在docker-compose.yml中设置标签,这也很好 . 我没有看到任何相关信息 .

Edit: traefik的docker日志显示UNIX套接字正在使用中:

time =“2018-07-23T10:55:38Z”level = error msg =“无法检索docker客户端和服务器主机的信息:无法连接到unix:/// var / run / docker的Docker守护程序 . 袜子 . 泊坞守护进程是否正在运行?“ time =“2018-07-23T10:55:38Z”level = error msg =“提供程序连接错误无法连接到unix:///var/run/docker.sock上的Docker守护程序 . 泊坞窗守护程序是否正在运行?,正在重试在13.276739006s“

Docker-compose should use npipe protocol on Windows by default,但显然不是't. Trying to set the Windows'管道,而不是UNIX套接字(using npipe of the long syntax):

#docker-compose.yml

version: '3.2'

services:

  traefik:
    image: traefik
    command: --api --docker
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - type: npipe                # here we are
        source: ./pipe
        target: /pipe/docker_engine

但日志仍显示:

time =“2018-07-23T10:57:18Z”level = error msg =“提供程序连接错误无法连接到unix:///var/run/docker.sock上的Docker守护程序 . 泊坞窗守护程序是否正在运行?”重试4.166259863s“time =”2018-07-23T10:57:23Z“level = error msg =”无法检索docker客户端和服务器主机的信息:无法连接到unix:/// var /上的Docker守护程序run / docker.sock.泊坞守护进程是否正在运行?“

2 回答

  • 6

    docker.sock文件位于linux环境中的/var/run/docker.sock,而不是当前目录 . 因此,在您的Linux环境示例中,卷装入不正确 . 该撰写文件看起来像:

    version: '3'
    
    services:
    
      traefik:
        image: traefik # The official Traefik docker image
        command: --api --docker
        ports:
          - "80:80"     # The HTTP port
          - "8080:8080" # The Web UI (enabled by --api)
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
    
      whoami:
          image: emilevauge/whoami 
          labels:
            - "traefik.frontend.rule=Host:whoami.docker.localhost"
    

    由于您在Windows上运行该命令,因此访问了docker api via an npipe or tcp connection . 解决方案似乎是(这可能取决于你的windows版本的docker):

    version: '3'
    
    services:
    
      traefik:
        image: traefik # The official Traefik docker image
        command: --api --docker --docker.endpoint=npipe:////./pipe/docker_engine
        ports:
          - "80:80"     # The HTTP port
          - "8080:8080" # The Web UI (enabled by --api)
        volumes:
          - //./pipe/docker_engine://./pipe/docker_engine
    
      whoami:
          image: emilevauge/whoami 
          labels:
            - "traefik.frontend.rule=Host:whoami.docker.localhost"
    
  • 1

    可以使用:

    volumes:
       - /var/run/docker.sock:/var/run/docker.sock
    

    只有在Powershell中使用此解决方法:

    $Env:COMPOSE_CONVERT_WINDOWS_PATHS=1
    

    原因是这个被打开的错误:https://github.com/docker/for-win/issues/1829这使得无法安装docker.sock,因为它是"not a valid Windows path"(错误) .

相关问题