【问题标题】:How to connect two local machines via docker swarm?如何通过 docker swarm 连接两台本地机器?
【发布时间】:2019-09-01 16:58:09
【问题描述】:

我想测试一些 docker swarm 功能,为此我有一台 Windows PC 和一台 mac book pro,都在我的私人网络中。

我安装了 Docker for Windows(Windows 10 pro,使用 linux 容器)和 Docker for mac。

然后我启动了它们并配置了我的路由器以允许 TCP 和 UDP 所需的端口:

  • 端口 2377 TCP 用于节点通信
  • 端口 7946 TCP/UDP 用于容器网络发现。
  • 容器入口网络的端口 4789 UDP。

我还停用了我的电脑和 Mac 上的防火墙。

然后我在我的 macbook 上运行 docker swarm init,它给了我一个加入令牌。

在我的 Windows PC 上,我在控制台中输入了加入命令,但......它失败了!

我收到一条以“...连接被拒绝”结尾的错误消息。

那么,您能给我一些建议或链接,说明如何通过 docker swarm 正确连接到本地机器吗?我很想对其进行测试并将其用于本地开发和测试我的应用程序。谢谢!

来自 Mac 的 Docker 信息

    $ docker info
    Containers: 2
     Running: 2
     Paused: 0
     Stopped: 0
    Images: 185
    Server Version: 18.03.1-ce
    Storage Driver: overlay2
     Backing Filesystem: extfs
     Supports d_type: true
     Native Overlay Diff: true
    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: v3fhiinezmdbbn98l0s6bgqzo
     Is Manager: true
     ClusterID: o9mcdlgtq37t5r86ganupstez
     Managers: 1
     Nodes: 1
     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.65.3
     Manager Addresses:
      192.168.65.3:2377
    Runtimes: runc
    Default Runtime: runc
    Init Binary: docker-init
    containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
    runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
    init version: 949e6fa
    Security Options:
     seccomp
      Profile: default
    Kernel Version: 4.9.87-linuxkit-aufs
    Operating System: Docker for Mac
    OSType: linux
    Architecture: x86_64
    CPUs: 4
    Total Memory: 4.095GiB
    Name: linuxkit-025000000001
    ID: 2D57:Q3QP:6UZ2:S6JV:WXLG:JN4H:TR6G:V3C3:P6ZP:2ENA:L7ES:OIJD
    Docker Root Dir: /var/lib/docker
    Debug Mode (client): false
    Debug Mode (server): false
    HTTP Proxy: docker.for.mac.http.internal:3128
    HTTPS Proxy: docker.for.mac.http.internal:3129
    Registry: https://index.docker.io/v1/
    Labels:
    Experimental: false
    Insecure Registries:
     127.0.0.0/8
    Live Restore Enabled: false

来自 Windows 的 Docker 信息

    $ docker info
    Containers: 0
     Running: 0
     Paused: 0
     Stopped: 0
    Images: 0
    Server Version: 18.09.2
    Storage Driver: overlay2
     Backing Filesystem: extfs
     Supports d_type: true
     Native Overlay Diff: true
    Logging Driver: json-file
    Cgroup Driver: cgroupfs
    Plugins:
     Volume: local
     Network: bridge host macvlan null overlay
     Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
    Swarm: inactive
    Runtimes: runc
    Default Runtime: runc
    Init Binary: docker-init
    containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
    runc version: 09c8266bf2fcf9519a651b04ae54c967b9ab86ec
    init version: fec3683
    Security Options:
     seccomp
      Profile: default
    Kernel Version: 4.9.125-linuxkit
    Operating System: Docker for Windows
    OSType: linux
    Architecture: x86_64
    CPUs: 3
    Total Memory: 7.768GiB
    Name: linuxkit-00155d674805
    ID: S7LD:PA6I:QGZR:YFQH:BR62:JS5C:DZLS:C6O3:RZUL:7ZXE:PRI6:HPRD
    Docker Root Dir: /var/lib/docker
    Debug Mode (client): false
    Debug Mode (server): true
     File Descriptors: 22
     Goroutines: 46
     System Time: 2019-04-11T13:28:11.3484452Z
     EventsListeners: 1
    Registry: https://index.docker.io/v1/
    Labels:
    Experimental: false
    Insecure Registries:
     127.0.0.0/8
    Live Restore Enabled: false
    Product License: Community Engine

Docker swarm join 命令输出

$ docker swarm join --token SWMTKN-1-5rp7ownwv3ob27vl52ogo8z6d3mbxasdfasdfsadfkrf8hqjk1b5-bi2p5u7i7blk5wepw389sba0w 192.168.x.x:2377
Error response from daemon: rpc error: code = Unavailable desc = all 
SubConns are in TransientFailure, latest connection error: 
connection error: 
desc = "transport: Error while dialing dial tcp 192.168.x.x:2377: 
connect: connection refused"

【问题讨论】:

  • “适当的容器”是什么意思? Windows 还是 linux 的?你有什么windows版本(内部版本号,用winver检查)?同时粘贴两个系统的 docker 信息输出。
  • 我正在使用 linux 容器。将尽快发布输出。
  • 我现在更新了我的问题
  • 我建议您使用 play-with-docker.com 测试 swarm 功能。

标签: docker devops docker-swarm docker-for-windows docker-for-mac


【解决方案1】:

问题在于,用于 Mac 的 netiher docker Desktop 和带有 Linux 容器的 Windows 都是“真正的”docker。两者都使用具有真正 docker 引擎工作的 Linux 操作系统的虚拟机。 如果我是正确的,192.162.65.3 不是你 Mac 的 IP,而是某个虚拟 mac 网络中 vm 的 IP。

根据这篇文章https://docs.docker.com/docker-for-mac/docker-toolbox/ 和这句话“另请注意,Docker Desktop for Mac 无法将流量路由到容器,因此您无法从主机直接访问正在运行的容器上的暴露端口。”在 Linux 容器上连接 Mac 和 Windows 可能并不容易。

我建议您获取一些云虚拟机或在 Windows 上进行测试,您可以使用 docker-machine 命令生成多个 Linux 虚拟机,您可以在这些虚拟机上设置本地集群来测试您希望的功能。

【讨论】:

  • 令人惊讶的是,在 2021 年仍然无法从 Windows 或 Mac 管理器创建多节点 Swarm:docs.docker.com/engine/swarm/swarm-tutorial。 “目前,您不能单独使用 Docker Desktop for Mac 或 Docker Desktop for Windows 来测试多节点集群”。
猜你喜欢
  • 1970-01-01
  • 2022-08-19
  • 2017-08-25
  • 1970-01-01
  • 1970-01-01
  • 2021-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多