Docker Container Interconnect

Source: Internet
Author: User
Tags docker run

Link mode

http://blog.csdn.net/halcyonbaby/article/details/42112325

The container is created by link, and then we can access it using the alias of the link container.
This will remove the application's reliance on the IP.
Unfortunately, the link method only solves the interconnection between single-machine containers. In multi-machine cases, the interconnection of containers requires other means.

[[email protected] ~]# Docker run-i-T mysql:latest/bin/bash[email protected]:/usr/local/mysql# IP Addr1:lo : MTU 65536 qdisc noqueue State UNKNOWN link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00 inet 127.0.0.1/8 SCOP E host lo Valid_lft forever Preferred_lft Forever Inet6:: 1/128 scope host Valid_lft Forever Preferred_lft FOREVER79:ETH0:MTU Qdisc Pfifo_fast State up Qlen, Link/ether 02:42:ac:11:00:04 BRD ff:ff:ff:ff:ff:ff in ET 172.17.0.4/16 scope global eth0 Valid_lft forever Preferred_lft forever inet6 fe80::42:acff:fe11:4/64 Scope Li   NK Valid_lft Forever Preferred_lft Forever [[email protected] ~]# Docker run-i-T--link=sad_bardeen:sql mysql:latest/bin/bash[email protected]:/usr/local/mysql# IP addr1:lo:mtu 65536 qdisc noqueue State UNKNOWN L Ink/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_l FT Forever Inet6:: 1/$ scope Host Valid_lft forever Preferred_lft FOREVER81:ETH0:MTU qdisc pfifo_fast State up Qlen-lin K/ether 02:42:ac:11:00:05 BRD ff:ff:ff:ff:ff:ff inet 172.17.0.5/16 scope global eth0 Valid_lft forever Preferred_ LFT Forever Inet6 fe80::42:acff:fe11:5/64 scope link Valid_lft forever preferred_lft forever[email protected ]:/usr/local/mysql# ping sqlping SQL (172.17.0.4): Data bytes56 bytes from 172.17.0.4:icmp_seq=0 ttl=64 time=0.114 ms# # #可以看出来, add a static dns[email protected]:/usr/local/mysql# cat/etc/hosts172.17.0.5 931c7ab8135e127.0.0.1 Localh ost::1 localhost ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 IP6 -allrouters172.17.0.4 SQL
Interconnect via container mode

As mentioned above, link only applies to a single host.
Two hosts, Docker officially recommends the following ways to connect two containers.
The following is an example of a wordpress+mysql service. WordPress and MySQL, deployed on two machines, are connected through a pair of ambassador.
WordPress (in Vm1)--link-->ambassador1 (in vm1)----socat--->ambassador2 (in vm2)--link--->mysql (in vm2)

启动mysql:sudo docker run -d --name mysql mysql启动ambassador1:sudo docker run -d --link mysql:mysql --name ambassador1 -p 3306:3306 ambassador  启动ambassador2:sudo docker run -d --name ambassador2 --expose 3306 -e MYSQL_PORT_3306_TCP=tcp://x.x.x.x:3306 ambassador  启动wordpress:sudo docker run -i -t --rm --link ambassador2:mysql wordpress

Reference:
http://blog.csdn.net/sunset108/article/details/40856957

Docker Container Interconnect

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.