运行 traekif 在 swarm 模式下有多个端口后端
Running traekif on swarm mode with a multiple ports backend
我在 Swarm 中使用 Traefik 时遇到了一些问题。通过以下配置,我希望端口 80 上的流量到达 traefik 服务,然后将其分派到 proxy 服务上的专用端口但是好像流量不通。
<pre></p>
<p>traefik:
image: traefik:1.3.5
command: --web --docker --docker.swarmmode --docker.watch --docker.domain=app.dev --logLevel=DEBUG
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /dev/null:/traefik.toml
deploy:
replicas: 1
placement:
constraints: [node.role == manager]
restart_policy:
condition: on-failure</p>
<p>proxy:
image: 'myapp/proxy'
deploy:
replicas: 1
labels:
- "traefik.backend=proxy"
- "traefik.web.frontend.rule=Host:www.app.dev"
- "traefik.web.port=8000"
- "traefik.wss.frontend.rule=Host:wss.app.dev"
- "traefik.wss.protocol=ws"
- "traefik.wss.port=9002"
- "traefik.api.frontend.rule=Host:api.app.dev"
- "traefik.api.port=8002"
- "traefik.lnr.frontend.rule=Host:lnr.app.dev"
- "traefik.lnr.port=9001"
restart_policy:
condition: on-failure
</pre>
我在日志中有以下条目:
<pre>
app_traefik.1.84giy7wqf3n6@moby | time="2017-08-08T11:27:34Z" level=debug msg="Filtering container without port and no traefik.port label app_proxy.1"
</pre>
我向应用程序发送请求时收到 404:
<pre>
curl -H "Host:www.app.dev" <a href="http://localhost" rel="nofollow noreferrer">http://localhost</a>
404 page not found
</pre>
在 运行 和 Docker Compose 时,是否在 Swarm 上下文中考虑了单个后端的多个端口?
知道我在这里遗漏了什么吗?
发现需要添加 traefik.port 和 traefik.frontend.rule,即使它们未被使用。
https://github.com/containous/traefik/issues/1840
我也遇到了同样的问题。我正在使用 docker compose for 运行 容器,我的服务中有两个开放端口,我想访问具有不同域的每个端口。我像下面这样解决
labels:
- "traefik.enable=true"
- "traefik.http.routers.s1.rule=Host(`sub1.sample.com`)"
- "traefik.http.routers.s1.entrypoints=websecure"
- "traefik.http.routers.s1.service=s1"
- "traefik.http.routers.s1.tls.certresolver=myhttps"
- "traefik.http.services.s1.loadbalancer.server.port=8543"
- "traefik.http.services.s1.loadbalancer.server.scheme=https"
- "traefik.http.routers.s1.rule=Host(`sub2.sample.com`)"
- "traefik.http.routers.s2.entrypoints=websecure"
- "traefik.http.routers.s2.service=s2"
- "traefik.http.routers.s2.tls.certresolver=myhttps"
- "traefik.http.services.s2.loadbalancer.server.port=9543"
- "traefik.http.services.s2.loadbalancer.server.scheme=https"
- "traefik.docker.network=traefik_default"
我还使用 letsencrypt 来处理 https
此外,我添加这一行是为了在 traefik 和我的容器之间建立安全连接
- "traefik.http.services.s2.loadbalancer.server.scheme=https"
如果你不需要https你可以省略这行
- "traefik.http.routers.s1.tls.certresolver=myhttps"
并在此行将 websecure 更改为 web
- "traefik.http.routers.s1.entrypoints=web"
我在 Swarm 中使用 Traefik 时遇到了一些问题。通过以下配置,我希望端口 80 上的流量到达 traefik 服务,然后将其分派到 proxy 服务上的专用端口但是好像流量不通。
<pre></p>
<p>traefik:
image: traefik:1.3.5
command: --web --docker --docker.swarmmode --docker.watch --docker.domain=app.dev --logLevel=DEBUG
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /dev/null:/traefik.toml
deploy:
replicas: 1
placement:
constraints: [node.role == manager]
restart_policy:
condition: on-failure</p>
<p>proxy:
image: 'myapp/proxy'
deploy:
replicas: 1
labels:
- "traefik.backend=proxy"
- "traefik.web.frontend.rule=Host:www.app.dev"
- "traefik.web.port=8000"
- "traefik.wss.frontend.rule=Host:wss.app.dev"
- "traefik.wss.protocol=ws"
- "traefik.wss.port=9002"
- "traefik.api.frontend.rule=Host:api.app.dev"
- "traefik.api.port=8002"
- "traefik.lnr.frontend.rule=Host:lnr.app.dev"
- "traefik.lnr.port=9001"
restart_policy:
condition: on-failure
</pre>
我在日志中有以下条目:
<pre>
app_traefik.1.84giy7wqf3n6@moby | time="2017-08-08T11:27:34Z" level=debug msg="Filtering container without port and no traefik.port label app_proxy.1"
</pre>
我向应用程序发送请求时收到 404:
<pre>
curl -H "Host:www.app.dev" <a href="http://localhost" rel="nofollow noreferrer">http://localhost</a>
404 page not found
</pre>
在 运行 和 Docker Compose 时,是否在 Swarm 上下文中考虑了单个后端的多个端口?
知道我在这里遗漏了什么吗?
发现需要添加 traefik.port 和 traefik.frontend.rule,即使它们未被使用。 https://github.com/containous/traefik/issues/1840
我也遇到了同样的问题。我正在使用 docker compose for 运行 容器,我的服务中有两个开放端口,我想访问具有不同域的每个端口。我像下面这样解决
labels:
- "traefik.enable=true"
- "traefik.http.routers.s1.rule=Host(`sub1.sample.com`)"
- "traefik.http.routers.s1.entrypoints=websecure"
- "traefik.http.routers.s1.service=s1"
- "traefik.http.routers.s1.tls.certresolver=myhttps"
- "traefik.http.services.s1.loadbalancer.server.port=8543"
- "traefik.http.services.s1.loadbalancer.server.scheme=https"
- "traefik.http.routers.s1.rule=Host(`sub2.sample.com`)"
- "traefik.http.routers.s2.entrypoints=websecure"
- "traefik.http.routers.s2.service=s2"
- "traefik.http.routers.s2.tls.certresolver=myhttps"
- "traefik.http.services.s2.loadbalancer.server.port=9543"
- "traefik.http.services.s2.loadbalancer.server.scheme=https"
- "traefik.docker.network=traefik_default"
我还使用 letsencrypt 来处理 https
此外,我添加这一行是为了在 traefik 和我的容器之间建立安全连接
- "traefik.http.services.s2.loadbalancer.server.scheme=https"
如果你不需要https你可以省略这行
- "traefik.http.routers.s1.tls.certresolver=myhttps"
并在此行将 websecure 更改为 web
- "traefik.http.routers.s1.entrypoints=web"