How to link Docker services across hosts?

前端 未结 8 1405
南笙
南笙 2021-01-29 17:51

Docker allows servers from multiple containers to connect to each other via links and service discovery. However, from what I can see this service discovery is host-local. I wou

8条回答
  •  醉话见心
    2021-01-29 18:36

    Weave is a new Docker virtual network technology that acts as a virtual ethernet switch over TCP/UDP - all you need is a Docker container running Weave on your host.

    What's interesting here is

    • Instead of links, use static IPs/hostnames in your virtual network
    • Hosts don't need full connectivity, a mesh is formed based on what peers are available, and packets will be routed multi-hop to where they need to go

    This leads to interesting scenarios like

    • Create a virtual network across the WAN, none of the Docker containers will know or care what actual network they sit in
    • Move your containers to different physical docker hosts, Weave will detect the peer accordingly

    For example, there's an example guide on how to create a multi-node Cassandra cluster across your laptop and a few cloud (EC2) hosts with two commands per host. I launched a CoreOS cluster with AWS CloudFormation, installed weave on each in /home/core, plus my laptop vagrant docker VM, and got a cluster up in under an hour. My laptop is firewalled but Weave seemed to be okay with that, it just connects out to its EC2 peers.

提交回复
热议问题