Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用docker的Traefik配置文件位置_Docker_Traefik - Fatal编程技术网

使用docker的Traefik配置文件位置

使用docker的Traefik配置文件位置,docker,traefik,Docker,Traefik,Traefik的guid很难以任何一步一步的方式遵循。它有以下问题: 建议将traefik作为命令运行,但不能在traefik图像上运行任何命令,您必须改用traefik:alpine,甚至使用docker exec-it…将其放入容器中 几乎没有提到traefik.toml文件 #1使新的读者对traefik是否打算作为一个容器运行感到困惑,该容器会根据新部署的容器自动更新,就像或者如果它打算在docker主机上运行一样 它们的原始docker compose.yml文件如下所示: versi

Traefik的guid很难以任何一步一步的方式遵循。它有以下问题:

  • 建议将
    traefik
    作为命令运行,但不能在
    traefik
    图像上运行任何命令,您必须改用
    traefik:alpine
    ,甚至使用
    docker exec-it…
    将其放入容器中
  • 几乎没有提到
    traefik.toml
    文件
  • #1使新的读者对traefik是否打算作为一个容器运行感到困惑,该容器会根据新部署的容器自动更新,就像或者如果它打算在docker主机上运行一样
  • 它们的原始
    docker compose.yml
    文件如下所示:

    version: '3' 
    
    services:
      reverse-proxy:
        image: traefik # The official Traefik docker image
        command: --api --docker #--consul --consul.endpoint=127.0.0.1:8500 # Enables the web UI and tells Traefik to listen to docker
        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
      whoami:
        image: containous/whoami # A container that exposes an API to show its IP address
        labels:
          - "traefik.frontend.rule=Host:whoami.docker.localhost"
    
    docker run -d -p 8080:8080 -p 80:80 -v $PWD/traefik.toml:/etc/traefik/traefik.toml traefik
    
    然后,您可以使用以下工具运行它:

    docker-compose up -d reverse-proxy
    
    这很好,您可以在此处添加新服务,并指定与上面类似的新标签,即
    traefik.frontend.rule=Host:whoami other.docker.localhost

    您可以使用curl测试这一点,如下所示指定主机标题:

    curl -H Host:whoami.docker.localhost http://127.0.0.1
    
    第1期)

    第5行必须更改为使用图像
    traefik:alpine

        image: traefik:alpine # The official Traefik docker image
    
    您现在可以实际
    docker exec
    此容器。您只能在阿尔卑斯山图像上使用
    sh
    (而不是
    /bin/bash
    )。我们现在可以执行以下操作:

    docker exec -it traefik_reverse-proxy_1 sh
    docker exec -it traefik_reverse-proxy_1 traefik --help
    
    第2期)

    在默认的
    docker compose.yml
    中,没有提到
    traefik.toml
    文件。即使我
    docker编写了up-d[一些新的服务]
    并可以访问这些服务,但将其放入容器中没有
    traefik.toml
    文件。它在容器中的任何地方都不存在,尽管它在容器的底部表示查找默认位置,如
    /etc/traefik/
    $HOME/.traefik/
    或工作目录。这是指主机还是容器?在容器中,我运行
    grep
    find
    ,只看到二进制文件:

    / # find / | grep traefik
    /usr/local/bin/traefik
    
    traefik是否在内存中存储我的服务配置

    文档()中的下一个逻辑页面立即开始详细说明
    traefik.toml
    的配置,但我必须使用这样的文件进行实验

    我不得不回头阅读页面底部的内容,发现当他们建议使用其官方图像并按如下方式运行时,必须在卷中指定使用静态
    traefik.toml
    文件:

    version: '3' 
    
    services:
      reverse-proxy:
        image: traefik # The official Traefik docker image
        command: --api --docker #--consul --consul.endpoint=127.0.0.1:8500 # Enables the web UI and tells Traefik to listen to docker
        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
      whoami:
        image: containous/whoami # A container that exposes an API to show its IP address
        labels:
          - "traefik.frontend.rule=Host:whoami.docker.localhost"
    
    docker run -d -p 8080:8080 -p 80:80 -v $PWD/traefik.toml:/etc/traefik/traefik.toml traefik
    
    因此,我将服务
    反向代理
    下原始
    docker compose.yml
    中的
    volumes
    部分更改为使用类似的内容:

    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
    
    即使这样,我也没有一个base
    traefik.toml
    文件可供使用(数据库中甚至没有)。我不得不去,但我甚至不确定它将如何应用于我运行的服务的现有配置(即
    whoami
    和/或
    whoami-other
    )。最后,在容器上运行
    find/| grep traefik
    会在
    /etc/traefik/traefik.toml
    中显示相同的
    traefik.toml
    文件,但它没有提到服务(我仍然可以使用
    curl-H Host:whoami.docker.localhost访问这些服务)http://127.0.0.1
    来自我的docker主机)那么配置在哪里?

    在这里
    不知怎的,traefik文档让新手(我)感到困惑。

    与其惹你生气,不如读一下文档。。。示例文件就在那里:在您编写docker命令之前的getting started中引用了。@Noki我认为这是traefik 1.7;PO使用traefik 2.x你能把你的toml文件粘贴在这里吗?我不知怎的无法访问它。@SemihKekül,PO,traefik<到2.x,因为他的docker compose中使用了前端标签file@Noki我认为你是对的,很抱歉,但是line:image:traefik的意思不是获取最新的图像,即2.x。如果是这种情况,PO的配置可能完全错误。