docker - Traefic docker 容器反向代理重定向到其他容器提供的端口失败:网关超时
问题描述
设置:我在一个 nas 设备上有各种原生应用程序和 docker 应用程序。(简单的例子)。
host
: 8080 (console)
: 81 (apache)
: <port> and more (individual nas applications)
- container:traefik
:80
- container:nginx
:90
- container:customcode
:4000
- and more (individual applications)
:<port>
(主机是 192.168.1.22)。
**所有容器和应用程序都可以工作并且可以通过“ http://192.168.1.22:<port>
”访问
我试图使用名称简单的 traefik 来管理端口。IE
'apache' 重定向到http://192.168.1.22:81(主机暴露) - 有效
'nas' 重定向到http://192.168.1.22:8080(主机暴露) - 有效
'nginx' 重定向到http://192.168.1.22:90(容器暴露) - 失败
traefik 设置能够重定向到主机本身的所有端口,但不会重定向到 docker 暴露的任何端口。这也适用于不同主机上的站点。对于容器公开的端口,我收到“网关超时”错误
(仅日志文件条目:)"'504 Gateway Timeout' caused by: dial tcp 192.168.1.22:90: i/o timeout"
。
我不能在容器上使用标签,因为它们不(有些不能)共享网络。我只想让 traefik 路由到 IP:Port 而不必担心端口是否由容器提供。
traefik.toml
loglevel = "ERROR"
[Log]
filePath = "/etc/traefik/traefik.log"
level = "DEBUG"
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[api]
dashboard = true
[providers.docker]
watch = false
exposedByDefault = false
endpoint = "unix:///var/run/docker.sock"
[providers.file]
watch = true
filename = "/etc/traefik/services.toml"
服务.toml
[http]
[http.services]
[http.services.nas]
[http.services.nas.loadBalancer]
[[http.services.nas.loadBalancer.servers]]
url = "http://192.168.1.22:8080/"
[http.services.test90]
[http.services.test90.loadBalancer]
[[http.services.test90.loadBalancer.servers]]
url = "http://192.168.1.22:90/" #this does not work#
[http.services.test81]
[http.services.test81.loadBalancer]
[[http.services.test81.loadBalancer.servers]]
url = "http://192.168.1.22:81/"
码头工人撰写:
version: "3.5"
services:
traefik:
image: "traefik:2.4"
container_name: "traefik"
restart: always
environment:
- PUID=<id>
- PGID=<id>
ports:
- "443:443"
- "80:80"
volumes:
- "/shr/traefik/:/etc/traefik/"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`traefik`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.entrypoints=http,https"
- "traefik.http.routers.traefik.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=admin:<pass>"
- "traefik.http.routers.nas.entrypoints=http"
- "traefik.http.routers.nas.rule=Host(`nas`)"
- "traefik.http.routers.nas.service=nas@file"
- "traefik.http.routers.test81.entrypoints=http"
- "traefik.http.routers.test81.rule=Host(`apache`)"
- "traefik.http.routers.test81.service=test81@file"
- "traefik.http.routers.test90.entrypoints=http"
- "traefik.http.routers.test90.rule=Host(`nginx`)"
- "traefik.http.routers.test90.service=test90@file"
networks:
- proxy
whoami:
image: "traefik/whoami"
container_name: "whoami"
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami`)"
- "traefik.http.routers.whoami.entrypoints=http"
networks:
- proxy
networks:
proxy:
external:
name: proxy
解决方案
似乎将 network_mode: "host" 添加到 docker-compose 并删除自定义网络解决了这个问题。
推荐阅读
- javascript - 没有在 req.body Express/node.js 中获取表单数据
- javascript - 如何使用 jQuery (.css) 添加多值(逗号分隔)框阴影?
- python - 训练模型无法保存 tensorflow keras
- javascript - 如何在单独的 JS 文件中使用 JSON 文件中的 JSON
- python - 在python中为字符串添加一个反斜杠(“\”)
- python - 如何在使用 numpy 创建的多维数组中查找特定元素的行号和列号?
- pandas - inplace=False 如何在数据框中不给出 keyerror
- laravel - 在 Laravel 的前端 vue.js 上未更新组件的内容
- postgresql - 其他用户的国家计数
- php - 我的 href 链接在我的 wordpress 按钮上不起作用