【问题标题】:init docker swarm with docker machine: context deadline exceeded使用 docker 机器初始化 docker swarm:超出上下文期限
【发布时间】:2018-01-03 17:39:16
【问题描述】:

我正在学习 Docker 机器,同时遇到一些问题。
我的电脑是mac,使用Docker for mac。我通过 docker-machine 创建了 2 个 vm、vm1 和 vm2,并尝试初始化一个拥有 nodes-vm1、vm2 和我的 mac 的集群。我的步骤如下:
1.创建一个名为“srinla/cms:latest”的镜像和一个docker-compose.yml

version: "3"
services:
  web:
    image: sprinla/cms:latest
    deploy:
      replicas: 1
    ports:
      - "80:80"
    networks:
      - webnet
    command: /data/start.sh
networks:
  webnet:

2.create 2 vms.Here is vm info:

yuxrdeMBP:~ yuxr$ docker-machine ls  
NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS  
vm1    -        virtualbox   Running   tcp://192.168.99.100:2376           v17.12.0-ce  
vm2    -        virtualbox   Running   tcp://192.168.99.101:2376           v17.12.0-ce  
  1. 在我的 mac 主机上初始化 swarm:
yuxrdeMBP:~ yuxr$ docker swarm init
Swarm initialized: current node (uf6rg1v91exlwntlskyj8iim7) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3qb32l84n0s8vl74rj9d6psm7bzdany3piw55ohtrq0q7ly814-c5km5zg3kj9d6vn6vrtt6xxtg 192.168.65.2:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

4加入vm1加入swarm,问题来了

yuxrdeMBP:~ yuxr$ docker-machine ssh vm1 "docker swarm join --token SWMTKN-1-3qb32l84n0s8vl74rj9d6psm7bzdany3piw55ohtrq0q7ly814-c5km5zg3kj9d6vn6vrtt6xxtg 192.168.65.2:2377"
Error response from daemon: Timeout was reached before node joined. The attempt to join the swarm will continue in the background. Use the "docker info" command to see the current swarm status of your node.
exit status 1

5.cat docker 日志:

time="2018-01-03T17:13:50.387854642Z" level=debug msg="Calling GET /_ping"
time="2018-01-03T17:13:50.388228524Z" level=debug msg="Calling GET /_ping"
time="2018-01-03T17:13:50.388521374Z" level=debug msg="Calling POST /v1.35/swarm/join"
time="2018-01-03T17:13:50.388583426Z" level=debug msg="form data: {\"AdvertiseAddr\":\"\",\"Availability\":\"\",\"DataPathAddr\":\"\",\"JoinToken\":\"*****\",\"ListenAddr\":\"0.0.0.0:2377\",\"RemoteAddrs\":[\"192.168.65.2:2377\"]}"
time="2018-01-03T17:13:55.392578452Z" level=error msg="failed to retrieve remote root CA certificate" error="rpc error: code = DeadlineExceeded desc = context deadline exceeded" module=node
time="2018-01-03T17:14:02.394608777Z" level=error msg="failed to retrieve remote root CA certificate" error="rpc error: code = DeadlineExceeded desc = context deadline exceeded" module=node
time="2018-01-03T17:14:09.395720474Z" level=error msg="failed to retrieve remote root CA certificate" error="rpc error: code = DeadlineExceeded desc = context deadline exceeded" module=node
time="2018-01-03T17:14:10.393743738Z" level=error msg="Handler for POST /v1.35/swarm/join returned error: Timeout was reached before node joined. The attempt to join the swarm will continue in the background. Use the \"docker info\" command to see the current swarm status of your node."
time="2018-01-03T17:14:16.398095265Z" level=error msg="failed to retrieve remote root CA certificate" error="rpc error: code = DeadlineExceeded desc = context deadline exceeded" module=node
time="2018-01-03T17:14:23.399587783Z" level=error msg="failed to retrieve remote root CA certificate" error="rpc error: code = DeadlineExceeded desc = context deadline exceeded" module=node
time="2018-01-03T17:14:25.399943337Z" level=error msg="cluster exited with error: rpc error: code = DeadlineExceeded desc = context deadline exceeded"
  1. 下面是我的 mac ifconfig 信息:

    yuxrdeMBP:~ yuxr$ ifconfig
    lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
      options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
      inet 127.0.0.1 netmask 0xff000000
      inet6 ::1 prefixlen 128
      inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
      nd6 options=201<PERFORMNUD,DAD>
    gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
    stf0: flags=0<> mtu 1280
    XHC20: flags=0<> mtu 0
    en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
      ether ac:bc:32:81:97:37
      inet6 fe80::4d8:6b2:718a:5d3b%en0 prefixlen 64 secured scopeid 0x5
      inet 192.168.199.169 netmask 0xffffff00 broadcast 192.168.199.255
      nd6 options=201<PERFORMNUD,DAD>
      media: autoselect
      status: active
    p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
      ether 0e:bc:32:81:97:37
      media: autoselect
      status: inactive
    awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
      ether 36:9f:65:fd:34:c3
      inet6 fe80::349f:65ff:fefd:34c3%awdl0 prefixlen 64 scopeid 0x7
      nd6 options=201<PERFORMNUD,DAD>
      media: autoselect
      status: active
    en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
      options=60<TSO4,TSO6>
      ether 6a:00:00:e3:4c:30
      media: autoselect <full-duplex>
      status: inactive
    en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
      options=60<TSO4,TSO6>
      ether 6a:00:00:e3:4c:31
      media: autoselect <full-duplex>
      status: inactive
    bridge0: flags=8822<BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500
      options=63<RXCSUM,TXCSUM,TSO4,TSO6>
      ether 6a:00:00:e3:4c:30
      Configuration:
          id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
          maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
          root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
          ipfilter disabled flags 0x2
      member: en1 flags=3<LEARNING,DISCOVER>
              ifmaxaddr 0 port 8 priority 0 path cost 0
      member: en2 flags=3<LEARNING,DISCOVER>
              ifmaxaddr 0 port 9 priority 0 path cost 0
      media: <unknown type>
      status: inactive
    utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
      options=6403<RXCSUM,TXCSUM,CHANNEL_IO,PARTIAL_CSUM,ZEROINVERT_CSUM>
      inet6 fe80::441e:c0e3:5429:2abb%utun0 prefixlen 64 scopeid 0xb
      nd6 options=201<PERFORMNUD,DAD>
    utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
      options=6403<RXCSUM,TXCSUM,CHANNEL_IO,PARTIAL_CSUM,ZEROINVERT_CSUM>
      inet6 fe80::7820:5bac:4735:7f82%utun1 prefixlen 64 scopeid 0xc
      inet6 fd44:5cb3:4ab4:5d08:7820:5bac:4735:7f82 prefixlen 64
      nd6 options=201<PERFORMNUD,DAD>
    utun2: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
      options=6403<RXCSUM,TXCSUM,CHANNEL_IO,PARTIAL_CSUM,ZEROINVERT_CSUM>
      inet6 fe80::26f2:e964:8dfb:e884%utun2 prefixlen 64 scopeid 0xd
      nd6 options=201<PERFORMNUD,DAD>
    gpd0: flags=8862<BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1400
      ether 02:50:41:00:01:01
    vboxnet0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
      ether 0a:00:27:00:00:00
      inet 192.168.99.1 netmask 0xffffff00 broadcast 192.168.99.255
    

为什么????
mac主机有ip,192.168.99.1,vm1有ip 192.168.99.100,vm2有ip 192.168.99.101,它们在同一个网络,为什么vm1和vm2不能 加入mac主机的群吗?

另一个问题:如果我使用vm1作为swarm manager,在mac主机上运行“docker swarm join”命令,当作为worker加入时,它可以加入但不能使用;当作为管理器加入时会出错:

yuxrdeMBP:~ yuxr$ docker swarm join --token SWMTKN-1-49w1hd28hs1mtj3sgmd0o3q7n59zgppvd18vs0iwhcnjemzmwb-7mk35zdnaslt1p41gninvwlud 192.168.99.100:2377
Error response from daemon: manager stopped: can't initialize raft node: rpc error: code = Unknown desc = could not connect to prospective new cluster member using its advertised address: rpc error: code = Unavailable desc = grpc: the connection is unavailable

谢谢你的帮助!!!

【问题讨论】:

  • 你是否已经离开了之前的 swarm 集群docker swarm leave 有时节点仍然连接到之前的 swarm。 .
  • 在我的例子中,工人和经理有不同版本的 Docker 引擎。在两个系统上安装 Docker Engine 20.10.13 后一切正常。

标签: docker docker-swarm docker-machine


【解决方案1】:

Mac 主机和 Docker for Mac 之间没有路由。所以在 Mac 上你只能在虚拟机之间设置多节点集群,而 Mac 的标准 Docker不能参与多节点集群。这是对在 OSX 上如何实现网络的限制。

请参阅documentation,其中对此进行了解释。 另请参阅此issue 了解更多背景信息。

【讨论】:

    【解决方案2】:

    对我来说,通过将安全组设置为 AWS 中的所有流量的入站规则来解决此错误。

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多