[英]Docker compose containers cannot access internet unless on host network - ipv6 only server
I am using docker compose on a IPv6 only Debian 11 server.我在仅 IPv6 的 Debian 11 服务器上使用 docker compose。 I am having trouble getting internet access from the containers.我无法从容器访问 Internet。 Communication between the containers works like a charm.容器之间的通信就像一个魅力。 However connecting to the ourside world does not.然而,连接到我们身边的世界却没有。 I can only ping to the outside world when I connect to the 'host' network (which I don't want to do for security reasons):当我连接到“主机”网络时,我只能 ping 到外部世界(出于安全原因,我不想这样做):
docker run -it --rm --network=host registry.ipv6.docker.com/library/alpine ping6 -c 2 google.com
^This resolved the address and pings alright. ^这解决了地址和 ping 问题。 With the default or the bridge network I get ping6: bad address 'google.com'
使用默认或桥接网络我得到ping6: bad address 'google.com'
My main question: What is the problem / how do I troubleshoot this?我的主要问题:问题是什么/我该如何解决这个问题?
I tried (in various combinations):我试过(各种组合):
{
"ipv6": true,
"fixed-cidr-v6": "fd00::/80",
"dns": ["2a01:7c8:7000:195::8:195:8", "2a01:7c8:7000:195::135:195:135"]
}
Note: I did not install a firewall at first.注意:我一开始没有安装防火墙。 During troubleshooting I installed uwf, which I did not configure and is currently disabled.在故障排除期间,我安装了 uwf,但我没有配置它,目前已禁用。
Hopefully this output will be helpful:希望这个输出会有所帮助:
With --network=host使用 --network=host
> docker run -it --rm --network=host registry.ipv6.docker.com/library/alpine cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.0.1 my-network
::1 my-network
> docker run -it --rm --network=host registry.ipv6.docker.com/library/alpine cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "resolvectl status" to see details about the actual nameservers.
nameserver 2a01:7c8:7000:195::8:195:8
nameserver 2a01:7c8:7000:195::135:195:135
> docker run -it --rm --network=host registry.ipv6.docker.com/library/alpine ping6 -c 2 google.com
PING google.com (2a00:1450:400e:810::200e): 56 data bytes
64 bytes from 2a00:1450:400e:810::200e: seq=0 ttl=118 time=3.365 ms
64 bytes from 2a00:1450:400e:810::200e: seq=1 ttl=118 time=2.848 ms
Without any network无需任何网络
> docker run -it --rm registry.ipv6.docker.com/library/alpine cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 e484aa610139
fd00::242:ac11:2 e484aa610139
> docker run -it --rm registry.ipv6.docker.com/library/alpine cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "resolvectl status" to see details about the actual nameservers.
nameserver 2a01:7c8:7000:195::8:195:8
nameserver 2a01:7c8:7000:195::135:195:135
> docker run -it --rm registry.ipv6.docker.com/library/alpine ping6 -c 2 google.com
ping6: bad address 'google.com'
Any help is greatly appreciated!任何帮助是极大的赞赏!
You either need to manually forward IPv6 traffic on your host to the specified docker network, or add:您要么需要手动将主机上的 IPv6 流量转发到指定的 docker 网络,要么添加:
{
"ipv6": true,
"fixed-cidr-v6": "fd00:ffff::/80",
"ip6tables": true,
"experimental": true
}
to your daemon.json which does this for you (like with IPv4).到您的 daemon.json 为您执行此操作(如使用 IPv4)。
Here is an Article going into more detail and explaining more alternatives (like the ipv6-nat docker image).这是一篇更详细的文章并解释了更多替代方案(如 ipv6-nat docker 映像)。
Be sure your cidr-v6 is part of the private Address range (fc00:: to fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff), otherwise it could be publicly exposed and accessed without a NAT thus becoming insecure.确保您的 cidr-v6 是私有地址范围的一部分(fc00:: 到 fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff),否则它可能会在没有 NAT 的情况下公开暴露和访问,从而变得不安全。
This is still experimental, and overall IPv6 on docker, especially docker-compose is not great这仍然是实验性的,docker 上的整体 IPv6,尤其是 docker-compose 不是很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.