同一覆盖网络中的Docker群集节点无法相互看到

时间:2018-01-06 00:45:12

标签: docker docker-swarm docker-networking docker-network

我的群体中有一个奇怪的问题,同一网络内的docker服务无法通信,当我尝试在它们之间进行通信时出现以下错误:

could not translate host name "dev_db" to address: Temporary failure in name resolution

我一直在调查他们是否在同一个网络上,并且根据检查他们是在同一个网络覆盖:

docker service inspect dev_slavedb
[
    {
        "ID": "flcwn7p17lgy6f9ad89iqas0e",
        "Version": {
            "Index": 68009
        },
        "CreatedAt": "2018-01-06T00:33:22.602060695Z",
        "UpdatedAt": "2018-01-06T00:33:22.603561612Z",
        "Spec": {
            "Name": "dev_slavedb",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "postgres:latest@sha256:3f4441460029e12905a5d447a3549ae2ac13323d045391b0cb0cf8b48ea17463",
                    "Env": [
                        "POSTGRES_USER=mydatabase",
                        "POSTGRES_PASSWORD=mydatabase"
                    ],
                    "Mounts": [
                        {
                            "Type": "volume",
                            "Source": "slave_postgres",
                            "Target": "/var/lib/postgresql/data"
                        }
                    ],
                    "StopGracePeriod": 10000000000,
                    "DNSConfig": {}
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "RestartPolicy": {
                    "Condition": "any",
                    "Delay": 5000000000,
                    "MaxAttempts": 0
                },
                "Placement": {
                    "Constraints": [
                        "node.hostname==swarm02"
                    ],
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        },
                        {
                            "OS": "linux"
                        },
                        {
                            "OS": "linux"
                        },
                        {
                            "Architecture": "arm64",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "386",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "ppc64le",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "s390x",
                            "OS": "linux"
                        }
                    ]
                },
                "Networks": [
                    {
                        "Target": "hh8zmhc9gx0p9iwukozo31dgs"
                    }
                ],
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "UpdateConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "RollbackConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "EndpointSpec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 5432,
                        "PublishedPort": 5432,
                        "PublishMode": "host"
                    }
                ]
            }
        },
        "Endpoint": {
            "Spec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 5432,
                        "PublishedPort": 5432,
                        "PublishMode": "host"
                    }
                ]
            },
            "Ports": [
                {
                    "Protocol": "tcp",
                    "TargetPort": 5432,
                    "PublishedPort": 5432,
                    "PublishMode": "host"
                }
            ],
            "VirtualIPs": [
                {
                    "NetworkID": "hh8zmhc9gx0p9iwukozo31dgs",
                    "Addr": "10.0.0.4/24"
                }
            ]
        }
    }
]





docker service inspect dev_db
[
    {
        "ID": "jqwmzoe57lonbr0wwnp262x9i",
        "Version": {
            "Index": 68001
        },
        "CreatedAt": "2018-01-06T00:30:50.284998521Z",
        "UpdatedAt": "2018-01-06T00:30:50.285963303Z",
        "Spec": {
            "Name": "dev_db",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "postgres:latest@sha256:3f4441460029e12905a5d447a3549ae2ac13323d045391b0cb0cf8b48ea17463",
                    "Env": [
                        "POSTGRES_USER=mydatabase",
                        "POSTGRES_PASSWORD=mydatabase"
                    ],
                    "Mounts": [
                        {
                            "Type": "volume",
                            "Source": "postgres",
                            "Target": "/var/lib/postgresql/data"
                        }
                    ],
                    "StopGracePeriod": 10000000000,
                    "DNSConfig": {}
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "RestartPolicy": {
                    "Condition": "any",
                    "Delay": 5000000000,
                    "MaxAttempts": 0
                },
                "Placement": {
                    "Constraints": [
                        "node.hostname==swarm01"
                    ],
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        },
                        {
                            "OS": "linux"
                        },
                        {
                            "OS": "linux"
                        },
                        {
                            "Architecture": "arm64",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "386",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "ppc64le",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "s390x",
                            "OS": "linux"
                        }
                    ]
                },
                "Networks": [
                    {
                        "Target": "hh8zmhc9gx0p9iwukozo31dgs"
                    }
                ],
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "UpdateConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "RollbackConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "EndpointSpec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 5432,
                        "PublishedPort": 5432,
                        "PublishMode": "host"
                    }
                ]
            }
        },
        "Endpoint": {
            "Spec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 5432,
                        "PublishedPort": 5432,
                        "PublishMode": "host"
                    }
                ]
            },
            "Ports": [
                {
                    "Protocol": "tcp",
                    "TargetPort": 5432,
                    "PublishedPort": 5432,
                    "PublishMode": "host"
                }
            ],
            "VirtualIPs": [
                {
                    "NetworkID": "hh8zmhc9gx0p9iwukozo31dgs",
                    "Addr": "10.0.0.2/24"
                }
            ]
        }
    }
]

即使我尝试使用他们的VIP(10.0.0.2和10.0.0.4),我也会得到同样的错误。我不知道如何解决这个问题,任何想法都值得赞赏。

2 个答案:

答案 0 :(得分:0)

我建议您尝试自己创建Overlay网络,以确保它确实有效。创建覆盖网络后,您可以根据需要将所有节点添加到子网并以这种方式访问​​它们,或者通过更复杂的路径,您可以在它们之间创建ssh通道,以确保您可以控制通信。

  1. 以下是创建叠加网络的方法
  2. Overlay-Network

答案 1 :(得分:0)

确保在每个Swarm节点上打开正确的防火墙端口以允许其他节点进入,否则不会发生DNS和其他通信等事件:

https://www.bretfisher.com/docker-swarm-firewall-ports/