首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法通过服务名访问docker-swarm容器

无法通过服务名访问docker-swarm容器
EN

Stack Overflow用户
提问于 2020-12-14 14:18:53
回答 1查看 300关注 0票数 1

我不能从docker swarm的同一覆盖网络上的另一个容器中通过它的服务名称来ping服务。我的步骤是:

代码语言:javascript
复制
# docker swarm init
# docker network create -d overlay --attachable net1
# docker service create --name dns1 --network net1 tutum/dnsutils sleep 3000
# docker service create --name dns2 --network net1 tutum/dnsutils sleep 3000

这创建了1节点群、用户定义的覆盖网络和2个服务。我应该能够执行到一个容器中,并通过服务名ping另一个容器,但它不起作用:

代码语言:javascript
复制
# docker exec -it dns1.1.6rned8409m9jkqoxgutzjz4y4 /bin/bash
root@05cba6fd8a0b:/# ping dns2
PING dns2 (10.0.5.5) 56(84) bytes of data.
From 05cba6fd8a0b (10.0.5.3) icmp_seq=1 Destination Host Unreachable
From 05cba6fd8a0b (10.0.5.3) icmp_seq=2 Destination Host Unreachable
From 05cba6fd8a0b (10.0.5.3) icmp_seq=3 Destination Host Unreachable
^C
--- dns2 ping statistics ---
4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3062ms

我可以通过全主机名(dns2.1.idkledfjgd5dwkv6piywpfk)或IP (10.0.5.6)直接ping容器。

环境信息:

代码语言:javascript
复制
# docker network inspect -v net1
[
    {
        "Name": "net1",
        "Id": "ngzwl7l7m0zb5brvee21mvfcz",
        "Created": "2020-12-14T22:05:25.962132239Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.5.0/24",
                    "Gateway": "10.0.5.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "05cba6fd8a0bc4e480b50f91fb395d27ee4998277d480109cb95249c38852909": {
                "Name": "dns1.1.6rned8409m9jkqoxgutzjz4y4",
                "EndpointID": "6bcc76c8688527fcf26d2ed313e351a54b8de69d28cde4388032849a2ff91a3e",
                "MacAddress": "02:42:0a:00:05:03",
                "IPv4Address": "10.0.5.3/24",
                "IPv6Address": ""
            },
            "c1d9252f528b177ac397b7b9bf627996993ddc0f54aad3ee3862d93dcac407a3": {
                "Name": "dns2.1.idkledfjgd5dwknv6pirywpfk",
                "EndpointID": "fafd8335715737c26c83ff8a3e7c52a302eb48cbb6b7bb75e396ed6a483bfd31",
                "MacAddress": "02:42:0a:00:05:06",
                "IPv4Address": "10.0.5.6/24",
                "IPv6Address": ""
            },
            "lb-net1": {
                "Name": "net1-endpoint",
                "EndpointID": "09e3b875528a05dc39a910b8cfe5cfd57756681c4aeffd56a0c9fb41d6bffd23",
                "MacAddress": "02:42:0a:00:05:04",
                "IPv4Address": "10.0.5.4/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4101"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "4dc98c7e5f08",
                "IP": "192.168.1.26"
            }
        ],
        "Services": {
            "dns1": {
                "VIP": "10.0.5.2",
                "Ports": [],
                "LocalLBIndex": 269,
                "Tasks": [
                    {
                        "Name": "dns1.1.6rned8409m9jkqoxgutzjz4y4",
                        "EndpointID": "6bcc76c8688527fcf26d2ed313e351a54b8de69d28cde4388032849a2ff91a3e",
                        "EndpointIP": "10.0.5.3",
                        "Info": {
                            "Host IP": "192.168.1.26"
                        }
                    }
                ]
            },
            "dns2": {
                "VIP": "10.0.5.5",
                "Ports": [],
                "LocalLBIndex": 270,
                "Tasks": [
                    {
                        "Name": "dns2.1.idkledfjgd5dwknv6pirywpfk",
                        "EndpointID": "fafd8335715737c26c83ff8a3e7c52a302eb48cbb6b7bb75e396ed6a483bfd31",
                        "EndpointIP": "10.0.5.6",
                        "Info": {
                            "Host IP": "192.168.1.26"
                        }
                    }
                ]
            }
        }
    }
]

代码语言:javascript
复制
# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.4.2-docker)

Server:
 Containers: 3
  Running: 2
  Paused: 0
  Stopped: 1
 Images: 7
 Server Version: 20.10.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: active
  NodeID: x2o135d3kkfxw6lb6mfyx8s3h
  Is Manager: true
  ClusterID: v5x80quwm3vwsubwdd6pclj4r
  Managers: 1
  Nodes: 1
  Default Address Pool: 10.0.0.0/8  
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 192.168.1.26
  Manager Addresses:
   192.168.1.26:2377
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.73-1-pve
 Operating System: Ubuntu 20.10
 OSType: linux
 Architecture: x86_64
 CPUs: 6
 Total Memory: 15.62GiB
 Name: dockerHost
 ID: CCGD:MQRE:PGJJ:YRU5:M4IM:5INT:EGA5:IER3:22UL:7CI3:PZOU:EZZ2
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio weight support
WARNING: No blkio weight_device support
EN

回答 1

Stack Overflow用户

发布于 2020-12-16 16:49:47

对于任何想要在未来看到这个的人。对我来说,问题是我在proxmox (ubuntu 20.04模板)上的LXC容器中运行docker。我在ubuntu 20.04虚拟机上测试了它,它完全按照预期工作。我不知道问题到底是什么,也不知道它是否可以修复,但基本上在LXC容器中运行它是不会起作用的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65284479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档