【问题标题】:Docker swarm container cannot resolve address of container in another nodeDocker swarm 容器无法解析另一个节点中容器的地址
【发布时间】:2018-10-26 10:47:50
【问题描述】:

我在我的 Vm 上初始化了一个 swarm,并以经理的身份将另一个 Vm 加入了我的 swarm。然后我覆盖一个网络docker network create --attachable --driver overlay my-net。

然后我运行 docker stack deploy 来部署我的服务。但是,当我执行到一个容器中并尝试从另一个节点 nslookup 容器时。例如nslookup <container_name>

我明白了:

Server:         127.0.0.11
Address:        127.0.0.11#53

** server can't find <container_name>: NXDOMAIN

nslookup 到同一节点中的容器虽然有效。

我猜我的 DNS 在从另一个节点解析地址时无法正常工作,我想知道为什么。

附加信息:

两个节点的netstat -l:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 *:ssh                   *:*                     LISTEN
tcp6       0      0 [::]:2377               [::]:*                  LISTEN
tcp6       0      0 [::]:7946               [::]:*                  LISTEN
tcp6       0      0 [::]:30283              [::]:*                  LISTEN
tcp6       0      0 [::]:30284              [::]:*                  LISTEN
tcp6       0      0 [::]:30285              [::]:*                  LISTEN
tcp6       0      0 [::]:30289              [::]:*                  LISTEN
tcp6       0      0 [::]:30290              [::]:*                  LISTEN
tcp6       0      0 [::]:30291              [::]:*                  LISTEN
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN
udp        0      0 *:bootpc                *:*
udp        0      0 *:4789                  *:*
udp6     768      0 [::]:7946               [::]:*

ufw 状态显示为非活动状态。

docker 检查(部分结果) 会不会是我的peer ip 10.0.0.5 不对?

"Peers": [
            {
                "Name": "c7feabf505ba",
                "IP": "10.0.0.5"
            },
            {
                "Name": "073e551404e8",
                "IP": "137.116.149.79"
            }
        ]

码头信息节点 1:

Containers: 2
 Running: 2
 Paused: 0
 Stopped: 0
Images: 15
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: ro2p9n7o33darkuylentq1nx0
 Is Manager: true
 ClusterID: 01q4hei9hzibq3x8m36pzqo8c
 Managers: 2
 Nodes: 2
 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: 168.63.239.163
 Manager Addresses:
  137.116.149.79:2377
  168.63.239.163:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-1025-azure
Operating System: Ubuntu 16.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.853GiB
Name: blockcord-staging2
ID: UT5F:4ZFW:4PRT:LGFS:JIV4:3YAD:DK5I:BIYL:FU6P:ZFEB:3OD3:U5EX
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

码头信息节点 2:

Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 15
Server Version: 18.06.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: osmwr2fcrcg8mazopkanf4gr7
 Is Manager: true
 ClusterID: 01q4hei9hzibq3x8m36pzqo8c
 Managers: 2
 Nodes: 2
 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: 10.0.1.6
 Manager Addresses:
  137.116.149.79:2377
  168.63.239.163:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d64c661f1d51c48782c9cec8fda7604785f93587
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-1025-azure
Operating System: Ubuntu 16.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.885GiB
Name: doc2us-staging
ID: JG7Q:HZBH:7WIF:22GC:PZQQ:EXJC:ZDPT:C2SA:TDRM:XJ4M:KKX4:OAEI
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

【问题讨论】:

  • 能否请您提供两个节点的 docker 信息状态?我怀疑它连接到同一个网络
  • 嗨@dotnetstep。我已经更新了新信息
  • 我现在还没有确切的答案,因为我必须进行实验,但以下事情是相似的:forums.docker.com/t/…

标签: docker docker-swarm


【解决方案1】:

原因是当我使用 docker swarm join 命令时,docker 会使用我的内部 ip 自动加入。

我必须这样做

docker swarm join --token ...... --advertise-addr .

感谢https://github.com/docker/swarmkit/issues/1429#issuecomment-329325410

【讨论】:

  • 谢谢,你拯救了我的一天!
  • 这里也一样,问题出在NAT后面的节点上,通过附加--advertise-addr &lt;public ip&gt;解决了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-12
  • 2019-04-28
  • 1970-01-01
  • 2019-01-30
相关资源
最近更新 更多