Programing

호스트에서 Docker 서비스를 연결하는 방법은 무엇입니까?

crosscheck 2020. 7. 22. 08:08
반응형

호스트에서 Docker 서비스를 연결하는 방법은 무엇입니까?


Docker를 사용하면 여러 컨테이너의 서버가 링크 및 서비스 검색을 통해 서로 연결할 수 있습니다 . 그러나 내가 볼 수있는 것에서이 서비스 검색은 호스트 로컬입니다. 다른 컴퓨터에서 호스팅되는 다른 서비스를 사용하는 서비스를 구현하고 싶습니다.

Docker에서이 문제를 해결하기위한 몇 가지 접근 방식이 있습니다 (예 : CoreOSjumpers , 기본적으로 다른 시스템에 프록시를 제공하는 호스트 로컬 서비스 및이 유스 케이스를 지원하려고 시도한 Docker 배치 관리를위한 수많은 github 프로젝트). .

개발 속도가 빠르면 현재 모범 사례를 따르기가 어렵습니다. 따라서 내 질문은 본질적으로 다음과 같습니다.

  1. Docker에서 호스트를 연결하는 현재의 주요 방법은 무엇입니까?
  2. Docker 시스템에서이 기능을 직접 지원할 계획이 있습니까?

최신 정보

Docker는 최근 Docker 오케스트레이션을위한 Swarm 이라는 새로운 도구를 발표 했습니다 .

Swarm을 사용하면 여러 도커 데몬을 "결합"할 수 있습니다. 먼저 웜을 생성하고 한 시스템에서 웜 관리자를 시작한 다음 웜 식별자를 사용하여 웜 관리자를 "결합"하는 도커 데몬을 갖습니다. 도커 클라이언트는 일반 도커 서버 인 것처럼 스웜 관리자에 연결합니다.

컨테이너가 Swarm으로 시작하면 정의 된 모든 제약 조건을 충족하는 사용 가능한 노드에 자동으로 할당됩니다. 다음 예는 블로그 게시물에서 가져 왔습니다.

$ docker run -d -P -e constraint:storage=ssd mysql

지원되는 제약 조건 중 하나는 "node"컨테이너를 특정 호스트 이름에 고정 할 수 있다는 것입니다. 웜은 또한 노드 전체의 링크를 해결합니다.

내 테스트에서 Swarm 이 아직 고정 위치의 볼륨에서 잘 작동하지 않는다는 인상을 받았습니다 (또는 적어도 연결 프로세스가 직관적이지 않음). 이것은 명심해야 할 것입니다.

군단 은 현재 베타 단계에 있습니다.


최근까지 Ambassador Pattern 은 원격 호스트 서비스 검색에 대한 유일한 Docker 기본 접근 방식이었습니다. 이 패턴은 여전히 ​​사용 가능하며 패턴이 프록시 역할을하는 하나 이상의 추가 컨테이너로 구성되어 있기 때문에 일반 Docker 이외의 마법이 필요하지 않습니다.

또한 Docker를 클러스터 가능하게 만드는 여러 가지 타사 확장이 있습니다. 타사 솔루션에는 다음이 포함됩니다.

  • 두 개의 호스트에서 Docker 네트워크 브리지를 연결하면 경량 및 다양한 솔루션이 있지만 일반적으로 몇 가지주의 사항이 있습니다.
  • skydock 및 SkyDNS 와 같은 DNS 기반 검색
  • 조선소 및 Docker 오케스트레이션 도구와 같은 Docker 관리 도구 광범위한 목록은 다음 질문을 참조하십시오. 프로덕션에서 Docker 컨테이너를 확장하는 방법

업데이트 3

Libswarm은 떼로 이름이 바뀌 었으며 이제는 별도의 응용 프로그램입니다.

시작점으로 사용할 github 페이지 데모는 다음과 같습니다.

# create a cluster
$ swarm create
6856663cdefdec325839a4b7e1de38e8

# on each of your nodes, start the swarm agent
#  <node_ip> 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=<node_ip:2375>

# start the manager on any machine or your laptop
$ swarm manage --token=6856663cdefdec325839a4b7e1de38e8 --addr=<swarm_ip:swarm_port>

# use the regular docker cli
$ docker -H <swarm_ip:swarm_port> info
$ docker -H <swarm_ip:swarm_port> run ... 
$ docker -H <swarm_ip:swarm_port> ps 
$ docker -H <swarm_ip:swarm_port> logs ...
...

# list nodes in your cluster
$ swarm list --token=6856663cdefdec325839a4b7e1de38e8
http://<node_ip:2375>

업데이트 2

공식적인 접근 방식은 사용에 지금 libswarm 데모를 참조 여기

최신 정보

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.


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.


Update

Docker 1.12 contains the so called swarm mode and also adds a service abstraction. They probably aren't mature enough for every use case, but I suggest you to keep them under observation. The swarm mode at least helps in a multi-host setup, which doesn't necessarily make linking easier. The Docker-internal DNS server (since 1.11) should help you to access container names, if they are well-known - meaning that the generated names in a Swarm context won't be so easy to address.


With the Docker 1.9 release you'll get built in multi host networking. They also provide an example script to easily provision a working cluster.

You'll need a K/V store (e.g. Consul) which allows to share state across the different Docker engines on every host. Every Docker engine need to be configured with that K/V store and you can then use Swarm to connect your hosts.

Then you create a new overlay network like this:

$ docker network create --driver overlay my-network

Containers can now be run with the network name as run parameter:

$ docker run -itd --net=my-network busybox

They can also be connected to a network when already running:

$ docker network connect my-network my-container

More details are available in the documentation.


The following article describes nicely how to connect docker containers on multiple hosts: http://goldmann.pl/blog/2014/01/21/connecting-docker-containers-on-multiple-hosts/


It is possible to bridge several Docker subnets together using Open vSwitch or Tinc. I have prepared Gists to show how to do it:

The advantage I see using this solution instead of the --link option and the ambassador pattern is that I find it more transparent: there is no need to have additional containers and more importantly, no need to expose ports on the host. Actually I think of the --link option to be a temporary hack before Docker get a nicer story about multi-host (or multi-daemon) setups.

Note: I know there is another answer pointing to my first Gist but I don't have enough karma to edit or comment on that answer.


As mentioned above, Weave is definitely a viable solution to link Docker containers across the hosts. Based on my own experience with it, it is fairly straightfoward to set it up. It is now also has DNS service which you can address container's by its DNS names.

On the other hand, there is CoreOS's Flannel and Juniper's Opencontrail for wiring the containers across the hosts.


Seems like docker swarm 1.14 allows you to:

  • assing hostname to container, using --hostname tag, but i haven't been able to make it work, containers are not able to ping each other by assigned hostnames.

  • assigning services to machine using --constraint 'node.hostname == <host>'

참고URL : https://stackoverflow.com/questions/21283517/how-to-link-docker-services-across-hosts

반응형