Dockone technology Sharing (10): Cross-host--link

Source: Internet
Author: User
Tags docker run etcd
This is a creation in Article, where the information may have evolved or changed.
"Editor's words" This technology sharing content is to do cross-host container location communication, replacing the--link can not cross the host and interoperability barriers.

Before reading this article, please read my previous article, which allows containers to access each other across hosts and learn from each other by making router broadcast routing entries.

To get all the Docker hosts in a LAN to know the next hop on the other side of the network, but after we've solved the need, another big question tells me that Docker will change its IP address after restarting the container or service.

Just like configuring the Cisco router's IP local pool (not the DHCP service) will not release the address pool and so on, so in the case of not easily fixed IP, I think of the domain name resolution. But how to let the DNS server to know the container's IP and name it? I looked up some information to find out that DDNS is well suited for this need. However, DDNS is in conjunction with DHCP, but Docker0 is not, and Docker containers do not request addresses from the DHCP server.

One day inadvertently saw the ETCD GitHub documentation, there are some open source software developed according to ETCD, not only service discovery, there are two DNS services. After comparing the study cost, I chose Skydns+etcd,skydns is written by Golang.

Just want to ETCD in the submission of information, Skydns can read, without restarting the service, this is very convenient, is how to let the container to tell ETCD domain name and IP address it? The benefit of Docker containers is that startup scripts can be customized.

I add a curl in the startup script or Etcdctl each time the container is started, the container reads its own hostname and the IP address is sent to the ETCD server.

For example, I have 2 tomcat and one nginx that are containerized:
Tomcat1.hypers.local tomcat2.hypers.local

In Nginx upstream, the address of the server becomes tomcat1.hypers.local:8080 tomcat2.hypers.local:8080. This way I forget the IP of the container and forget which host it is on.

As long as DNS can resolve their IP, because the Docker container is the host nameserver, so this DNS how to specify the address need not worry. As long as the host is Skydns address on the line, start Etcd+skydns is very simple, ETCD start command I want you to play k8s metropolis.

The Skydns is 0 configured and can read the Skydns information in the ETCD. can also own Skydns-after the parameter to start, I have Skydns Docker, do not trouble everyone compiled, in the Spirit Sparrow Cloud Georce Warehouse can find.

Skydns is built on the ETCD server.

Curl-xput http://127.0.0.1:4001/v2/keys/skydns/config \
-D value= ' {"dns_addr": "0.0.0.0:53", "Domain": ". Local.", "nameservers": ["223.5.5.5:53", "114.114.114.114:53"]} '

Docker Pull Index.alauda.cn/georce/skydns

Docker RUN-ITD--name=skydns--net=host Index.alauda.cn/georce/skydns

Container startup script

Curl-xput/http $ETCD: 4001/v2/keys/skydns/local/$DOMAIN/"' Hostname-s '" \
-D value= ' {"host": "' IP A | grep "Scope Global eth0" | awk ' {print$2} ' | Grep-o ' \ ([0-9]\{1,3\}\.\) \{3\}[0-9]\{1,3\} ' "} '

Etcdctl-c $ETCD _host:4001--no-sync set/skydns/local/$DOMAIN/"' hostname-s '" ' {"HOST": "' IP A | grep "Scope Global eth0" | Grep-o ' \ ([0-9]\{1,3\}\.\) \{3\}[0-9]\{1,3\} ' "} '


These two commands represent the same meaning, hostname is based on the command when the container is started, such as docker run -itd --name=java --hostname=tomcat1

$DOMAIN is Docker run-itd-e domain=hypers

I'm using the local last root domain by default, which is tomcat1.hypers.local. Just like my network that article at last use Win7 to visit the Nginx mapped by the unprovoked port. Nginx.hypers.local is also accessible as long as my Win7 DNS is pointing to Skydns.

Skydns can set up DNS to be forwarded to 223.5.5.5 or 114.114.114.114 so there is no need to worry about the Internet.

The above content is organized according to the June 30, 2015 Night Group sharing content. Share people Wu Jian, the leading big data analyst company in Shanghai Hypers, participated in the "Lark Docker Mega Fun" and won the first prize。 Dockone organizes targeted technology sharing every week and welcomes interested students to participate.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.