无法将 Docker DNS 与 nftables 一起使用

无法将 Docker DNS 与 nftables 一起使用

我有一个在 10.64.128.53 上运行的 bind9 DNS 容器,它位于子网 10.64.128.0/24 上的 docker 网络“服务器”上。这工作正常,如果我运行: nslookup google.com 10.64.128.53

我得到输出:

Server:         10.64.128.53
Address:        10.64.128.53#53

Non-authoritative answer:
Name:   google.com
Address: 216.58.193.142

当我在 Docker 容器中运行相同的命令时:docker run --rm -it --network servers --dns 10.64.128.53 alpine nslookup google.com 10.64.1 28.53

我得到输出:

Server:         10.64.128.53
Address:        10.64.128.53:53

Non-authoritative answer:
Name:   google.com
Address: 216.58.193.142

这是预期的现在如果我运行:docker run --rm -it --network servers --dns 10.64.128.53 alpine nslookup google.com 我得到输出:

nslookup: write to '127.0.0.11': Connection refused
;; connection timed out; no servers could be reached

这对我来说没有多大意义,因为我指定了我的 docker DNS 服务器,但我假设 docker 通过 127.0.0.11 上的内部代理运行它。如果我使用它,这会很棒,但我不需要它。我能想到的最好的解决方案是/etc/resolv.conf使用我的 DNS 服务器进行覆盖,但这似乎是一个糟糕的解决方案。我看到了这个https://github.com/moby/moby/issues/19474#issuecomment-173093011但无法在 nftables 中使其工作,但我猜这是唯一的方法,因为 docker DNS 服务器似乎需要来自 127.0.0.11:53 的连接

主机是 Gentoo Linux,我知道安装 iptables 后网络就可以正常工作。每当我启动虚拟机时,我都会在 dockers 的日志中看到这些错误:

time="2022-01-25T03:08:56Z" level=warning msg="Failed to find iptables: exec: \"iptables\": executable file not found in $PATH"
time="2022-01-25T03:08:56Z" level=error msg="set up rule failed, [-t nat -I DOCKER_OUTPUT -d 127.0.0.11 -p udp --dport 53 -j DNAT --to-destination 127.0.0.11:50360]"
time="2022-01-25T03:08:56Z" level=error msg="set up rule failed, [-t nat -I DOCKER_POSTROUTING -s 127.0.0.11 -p udp --sport 50360 -j SNAT --to-source :53]"
time="2022-01-25T03:08:56Z" level=error msg="set up rule failed, [-t nat -I DOCKER_OUTPUT -d 127.0.0.11 -p tcp --dport 53 -j DNAT --to-destination 127.0.0.11:46531]"
time="2022-01-25T03:08:56Z" level=error msg="set up rule failed, [-t nat -I DOCKER_POSTROUTING -s 127.0.0.11 -p tcp --sport 46531 -j SNAT --to-source :53]"

每次我尝试在 docker 容器中运行 nslookup 命令时也会看到此错误,但我不确定它有多大关系:

time="2022-01-25T03:20:08.094540639Z" level=error msg="Handler for POST /v1.41/exec/d52b964c2e34acb78b67e5d2f02a8143e1efb3c45da0936fe128ed14fb6296ce/resize returned error: cannot resize a stopped container: unknown"

仅仅使用 iptables 并不是真正的解决方案,我希望它纯粹是 nftables,这似乎并不不合理。

如果我运行 iptables,Docker DNS 似乎可以工作,但没有向 iptables 添加任何规则。我不明白这一点,为什么它需要 iptables 但不制定任何规则?

相关内容