简体   繁体   English

Docker 群容器无法访问 inte.net

[英]Docker swarm containers not able to access internet

I am trying to setup a swarm cluster in AWS, however the containers in the host are not able to access the inte.net.我正在尝试在 AWS 中设置一个 swarm 集群,但是主机中的容器无法访问 inte.net。 The ping command for both address resolution or direct connectivity via IP is not working from inside the container.通过 IP 进行地址解析或直接连接的 ping 命令在容器内部不起作用。

Before creating this ticket I had a look at this issue, but I don't think there is CIDR overlap in my case.在创建这张票之前,我查看了这个问题,但我认为在我的案例中没有 CIDR 重叠。

I have the following configurations:我有以下配置:

Public Subnet CIDR : 10.2.1.0/24
Namespace server inside this is :10.2.0.2

Ingress overlay network --> 10.255.0.0/16

docker_gwbridge --> 172.18.0.0/1

I have also tried creating the new overlay(192.168.1.0/24) and docker_gwbridge(10.11.0.0/16).network with no luck.我也尝试过创建新的 overlay(192.168.1.0/24) 和 docker_gwbridge(10.11.0.0/16).network 但没有成功。

I am creating the service with these options(removing the mount and env parameters):我正在使用这些选项创建服务(删除 mount 和 env 参数):

docker service create --publish 8098:8098 <Imagename>

Please note when I was creating the overlay.network by myself I was adding the option -.network my-overlay as well in the create command.请注意,当我自己创建 overlay.network 时,我也在创建命令中添加了选项-.network my-overlay

Any pointers as to what I might be missing/doing wrong?关于我可能遗漏/做错了什么的任何指示?

Edit 1 Adding more info编辑 1 添加更多信息

Below is the inspect of container when I am not creating a new overlay.network and going with the default one:下面是当我没有创建新的 overlay.network 并使用默认的容器时对容器的检查:

"NetworkSettings": {
        "Bridge": "",
        "SandboxID": "eb***",
        "HairpinMode": false,
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "Ports": {
            "5005/tcp": null,
            "8080/tcp": null
        },
        "SandboxKey": "/var/run/docker/netns/e***9",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null,
        "EndpointID": "",
        "Gateway": "",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "IPAddress": "",
        "IPPrefixLen": 0,
        "IPv6Gateway": "",
        "MacAddress": "",
        "Networks": {
            "ingress": {
                "IPAMConfig": {
                    "IPv4Address": "10.255.0.4"
                },
                "Links": null,
                "Aliases": [
                    "30**"
                ],
                "NetworkID": "g7w**",
                "EndpointID": "291***",
                "Gateway": "",
                "IPAddress": "10.255.0.4",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "02:4***"
            }

And below is from when I am creating the overlay.network:以下是我创建 overlay.network 时的内容:

"Networks": {
            "ingress": {
                "IPAMConfig": {
                    "IPv4Address": "10.255.0.4"
                },
                "Links": null,
                "Aliases": [
                    "42***"
                ],
                "NetworkID": "jl***3",
                "EndpointID": "792***86c",
                "Gateway": "",
                "IPAddress": "10.255.0.4",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "02:4***"
            },
            "my-overlay": {
                "IPAMConfig": {
                    "IPv4Address": "192.168.1.3"
                },
                "Links": null,
                "Aliases": [
                    "42**"
                ],
                "NetworkID": "4q***",
                "EndpointID": "4c***503",
                "Gateway": "",
                "IPAddress": "192.168.1.3",
                "IPPrefixLen": 24,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "02:4***"
            }

I am answering my question as I found out that the reason for this behavior was my custom chef recipe for docker installation.我正在回答我的问题,因为我发现这种行为的原因是我用于 docker 安装的自定义厨师食谱。 I was setting up iptables=false in the docker config and hence it was not working for any docker container other than those in host network mode.我在 docker 配置中设置了 iptables=false,因此它不适用于主机网络模式以外的任何 docker 容器。

I got the following advice from Bret(Docker champion in docker community) which helped me to get to the root of the problem.我从 Bret(docker 社区中的 Docker 冠军)那里得到了以下建议,这帮助我找到了问题的根源。 In short it was a issue with something I was doing wrongly, however posting the suggestion below in case you want to troubleshoot such issues in future.简而言之,这是我做错的事情的问题,但是如果您想在将来解决此类问题,请在下面发布建议。

Hey Manish,嘿,曼尼什,

Suggestion: get a single container working correctly without swarm or overlays before trying them.建议:在尝试之前,让单个容器在没有群或覆盖的情况下正常工作。

so you should be able to just docker run --rm nginx:alpine ping 8.8.8.8 and get a response.所以你应该能够 docker run --rm nginx:alpine ping 8.8.8.8 并得到响应。

That verifies that containers on that host have a way to the internet.这验证了该主机上的容器是否可以访问 Internet。

Then trying docker run --rm nginx:alpine ping google.com and get a response.然后尝试 docker run --rm nginx:alpine ping google.com 并获得响应。

That verifies DNS resolution is working.这将验证 DNS 解析是否有效。

*Then you can try creating a single overlay network on one node in a single node swarm:* *然后您可以尝试在单节点群中的一个节点创建单个覆盖网络:*

*docker swarm init * *码头群初始化*

*docker network create --driver overlay --attachable mynet * *docker network create --driver overlay --attachable mynet *

*docker run --rm --network mynet nginx:alpine ping google.com * *docker run --rm --network mynet nginx:alpine ping google.com *

That verifies they have internet and DNS on a overlay network.这验证了他们在覆盖网络上拥有互联网和 DNS。

If you then add multiple nodes and have issues, then you likely need to ensure all swarm nodes can talk over swarm ports, which you find a link to the firewall port list in The Swarm Section under the Creating a 3-Node Swarm Cluster resources.如果您随后添加多个节点并遇到问题,那么您可能需要确保所有 swarm 节点都可以通过 swarm 端口进行通信,您可以在创建 3 节点 Swarm 集群资源下的 Swarm 部分中找到防火墙端口列​​表的链接。

As Manish said, first try to ping public network without overlay network:正如Manish所说,首先尝试在没有覆盖网络的情况下ping公共网络:

docker run --rm nginx:alpine ping 8.8.8.8

If it doesn't work, then you have a problem with firewall or something else.如果它不起作用,那么你的防火墙或其他东西有问题。 In my case, iptables firewall restricted DOCKER-USER chain to get access public network.就我而言,iptables 防火墙限制 DOCKER-USER 链访问公共网络。 So I have flushed all docker rules:所以我刷新了所有 docker 规则:

sudo iptables -F DOCKER-USER

Then reinitialized:然后重新初始化:

sudo iptables -I DOCKER-USER -i eth0 -s 0.0.0.0/0 -j ACCEPT

I had a similar issue and was able to fix it by configuring the daemon.json file in the /etc/docker directory.我有一个类似的问题,并且能够通过在 /etc/docker 目录中配置 daemon.json 文件来修复它。 Add following lines if they are not present already.如果它们不存在,请添加以下行。

{
   "iptables":true,
   "dns": ["8.8.8.8", "8.8.4.4"]
}

Then restart the docker service然后重启docker服务

sudo service docker restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM