无法在 docker-compose.yml 内通过 "labels" 设置 Traefik
Cannot set Traefik via "labels" inside docker-compose.yml
Traefik 简单地忽略 "labels" 配置。
跟随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"
然后,运行ning docker-compose 应该足够了(没有 traefik.toml 文件):
docker-compose up -d
预期结果:
Starting test_traefik_1 ... done
Starting test_whoami_1 ... done
但不幸的是,Traefik 的仪表板没有显示任何内容:
No providers found
我尝试过什么:
- 要同时使用另一种 labels 表示法:
labels:
traefik.backend: "whoami"
traefik.frontend.rule: "Host: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:
volumes:
- type: npipe
source: ./pipe
target: /pipe/docker_engine
没有任何效果。
现在,我可以在仪表板中看到某些内容的唯一方法是将此行添加到 Traefik 卷:“-./traefik.toml:/traefik.toml”,同时创建 "traefik.toml" 文件与 [文件] 配置。我不想拥有这个文件。我想在 docker-compose.yml.
内的 "lables" 内进行控制
知道什么时候应该使用 traefik.toml 文件,而不是在 docker-compose.yml 中设置标签,这也很好。我没有看到任何相关信息。
编辑: docker traefik 的日志显示正在使用 UNIX 套接字:
time="2018-07-23T10:55:38Z" level=error msg="Failed to retrieve
information of the docker client and server host: Cannot connect to
the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon
running?"
time="2018-07-23T10:55:38Z" level=error msg="Provider
connection error Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon running?, retrying
in 13.276739006s"
Docker-撰写should use npipe protocol on Windows by default, but it doesn't. Trying to set the Windows' pipe explicitly, to take place instead of the UNIX socket (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="Provider connection error
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is
the docker daemon running?, retrying in 4.166259863s"
time="2018-07-23T10:57:23Z" level=error msg="Failed to retrieve
information of the docker client and server host: Cannot connect to
the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon
running?"
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"
可以使用:
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"(错误)。
Traefik 简单地忽略 "labels" 配置。
跟随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"
然后,运行ning docker-compose 应该足够了(没有 traefik.toml 文件):
docker-compose up -d
预期结果:
Starting test_traefik_1 ... done
Starting test_whoami_1 ... done
但不幸的是,Traefik 的仪表板没有显示任何内容:
No providers found
我尝试过什么:
- 要同时使用另一种 labels 表示法:
labels: traefik.backend: "whoami" traefik.frontend.rule: "Host: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:
volumes: - type: npipe source: ./pipe target: /pipe/docker_engine
没有任何效果。
现在,我可以在仪表板中看到某些内容的唯一方法是将此行添加到 Traefik 卷:“-./traefik.toml:/traefik.toml”,同时创建 "traefik.toml" 文件与 [文件] 配置。我不想拥有这个文件。我想在 docker-compose.yml.
内的 "lables" 内进行控制知道什么时候应该使用 traefik.toml 文件,而不是在 docker-compose.yml 中设置标签,这也很好。我没有看到任何相关信息。
编辑: docker traefik 的日志显示正在使用 UNIX 套接字:
time="2018-07-23T10:55:38Z" level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
time="2018-07-23T10:55:38Z" level=error msg="Provider connection error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, retrying in 13.276739006s"
Docker-撰写should use npipe protocol on Windows by default, but it doesn't. Trying to set the Windows' pipe explicitly, to take place instead of the UNIX socket (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="Provider connection error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, retrying in 4.166259863s"
time="2018-07-23T10:57:23Z" level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
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"
可以使用:
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"(错误)。