小编tou*_*ste的帖子

使用traefik无法获取正确的容器IP

当使用Traefik和Docker-compose时,我想获取容器IP来执行基于IP的过滤,但改为获取docker网络网关IP。

以下是来自curl-client容器的curl请求的结果:

docker-compose exec curl-client curl https://whoami.domain.name

Hostname: 608f3dcaf7d9
IP: 127.0.0.1
IP: 172.18.0.2
GET / HTTP/1.1
Host: whoami.domain.name
User-Agent: curl/7.58.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.18.0.1
X-Forwarded-Host: whoami.domain.name
X-Forwarded-Port: 443
X-Forwarded-Proto: https
X-Forwarded-Server: 88756553599b
X-Real-Ip: 172.18.0.1    
Run Code Online (Sandbox Code Playgroud)

这里,172.18.0.1 是 traefik_net 网络的网关。相反,我希望在 X-Forwarded-For 字段中看到 172.18.0.9,因为它是curl-client 容器的 IP:

docker-compose exec curl-client cat /etc/hosts

172.18.0.9      34f7b6e5472f
Run Code Online (Sandbox Code Playgroud)

我还尝试使用 'traefik.frontend.whiteList.useXForwardedFor=true' 选项但没有成功。

traefik.toml

logLevel = "ERROR"

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.dashboard]
    address = ":8080"
  [entryPoints.http]
    address = ":80"
    [entryPoints.http.redirect]
      entryPoint = "https"
  [entryPoints.https]
    address = ":443" …
Run Code Online (Sandbox Code Playgroud)

docker docker-compose traefik

5
推荐指数
1
解决办法
9140
查看次数

标签 统计

docker ×1

docker-compose ×1

traefik ×1