Tec*_*dom 2 reverse-proxy docker docker-compose traefik
Traefik完全忽略了"标签"配置.
按照Traefik的主要文档页面,我们可以简单地做到:
#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"
Run Code Online (Sandbox Code Playgroud)
然后,运行docker-compose就足够了(没有traefik.toml文件):
docker-compose up -d
Run Code Online (Sandbox Code Playgroud)
结果在预期中:
Starting test_traefik_1 ... done
Starting test_whoami_1 ... done
Run Code Online (Sandbox Code Playgroud)
但不幸的是,Traefik的仪表板没有显示任何内容:
找不到供应商
我试图做什么:
Run Code Online (Sandbox Code Playgroud)labels: traefik.backend: "whoami" traefik.frontend.rule: "Host:whoami.docker.localhost"
$env:DOCKER_HOST="npipe:////./pipe/docker_engine"或$env:DOCKER_HOST="tcp://localhost:2375"在Powershell上运行.Run Code Online (Sandbox Code Playgroud)volumes: - type: npipe source: ./pipe target: /pipe/docker_engine
什么都行不通.
现在,我可以在仪表板中查看内容的唯一方法是将此行添加到Traefik卷:" - ./traefik.toml:/traefik.toml",同时使用[file]配置创建"traefik.toml"文件.我不想拥有这个文件.我想把控件放在docker-compose.yml里面的"标签"里面.
知道我应该何时使用traefik.toml文件,而不是在docker-compose.yml中设置标签,这也很好.我没有看到任何相关信息.
编辑: traefik的docker日志显示UNIX套接字正在使用中:
time ="2018-07-23T10:55:38Z"level = error msg ="无法检索docker客户端和服务器主机的信息:无法连接到unix上的Docker守护进程:///var/run/docker.sock Docker守护程序是否正在运行?"
time ="2018-07-23T10:55:38Z"level = error msg ="提供程序连接错误无法连接到unix:///var/run/docker.sock上的Docker守护程序.泊坞守护程序是否正在运行?,正在重试在13.276739006s"
Docker-compose 默认情况下应该在Windows上使用npipe协议,但事实并非如此.尝试显式设置Windows管道,而不是UNIX套接字(使用长语法的npipe):
#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
Run Code Online (Sandbox Code Playgroud)
但日志仍显示:
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上的Docker守护程序:///var/run/docker.sock Docker守护程序是否正在运行?"
可以使用:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Run Code Online (Sandbox Code Playgroud)
只有在Powershell中使用此解决方法:
$Env:COMPOSE_CONVERT_WINDOWS_PATHS=1
Run Code Online (Sandbox Code Playgroud)
原因是这个被打开的错误:https://github.com/docker/for-win/issues/1829 这使得无法安装docker.sock,因为它"不是有效的Windows路径"(错误).
| 归档时间: |
|
| 查看次数: |
2463 次 |
| 最近记录: |