How to link Docker services across hosts?

前端 未结 8 1502
南笙
南笙 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:21

    UPDATE 3

    Libswarm has been renamed as swarm and is now a separate application.

    Here is the github page demo to use as a starting point:

    # create a cluster
    $ swarm create
    6856663cdefdec325839a4b7e1de38e8
    
    # on each of your nodes, start the swarm agent
    #   doesn't have to be public (eg. 192.168.0.X),
    #  as long as the other nodes can reach it, it is fine.
    $ swarm join --token=6856663cdefdec325839a4b7e1de38e8 --addr=
    
    # start the manager on any machine or your laptop
    $ swarm manage --token=6856663cdefdec325839a4b7e1de38e8 --addr=
    
    # use the regular docker cli
    $ docker -H  info
    $ docker -H  run ... 
    $ docker -H  ps 
    $ docker -H  logs ...
    ...
    
    # list nodes in your cluster
    $ swarm list --token=6856663cdefdec325839a4b7e1de38e8
    http://
    

    UPDATE 2

    The official approach is now to use libswarm see a demo here

    UPDATE

    There is a nice gist for openvswitch hosts communication in docker using the same approach.

    To allow service discovery there is an interesting approach based on DNS called skydock.

    There is also a screencast.


    This is also a nice article using the same pieces of the puzzle but adding also vlans on top:

    http://fbevmware.blogspot.it/2013/12/coupling-docker-and-open-vswitch.html

    The patching has nothing to do with the robustness of the solution. Docker is actually only a sort of DSL upon Linux Containers and both solutions in these articles simply bypass some Docker automatic settings and fall back directly to Linux Containers.

    So you can use the solutions safely and wait to be able to do it in a simpler way once Docker will implement it.

提交回复
热议问题