Docker Network working principle detailed _docker

Source: Internet
Author: User
Tags uuid nameserver docker run

Docker Network Working principle

When the Docker server is Docker daemon starts, it automatically creates a bridge with a name of Docker0, and whenever Docker creates a container, it creates a veth* port on the host named Ethernet. and add this eth* to Docker0 Bridge, in the container will automatically create a name is eth0 Ethernet port, this eth0 and veth* will form a similar pipe to the pair, the corresponding.

Configuring DNS

Docker how to allocate each container hostname and DNS configuration, you can see something by the Mount command in contain:

Mount

...
/DEV/DISK/BY-UUID/5F3D0920-98A8-434A-9C02-8163DCCF6C62 on/etc/resolv.conf type EXT4 (Rw,relatime,errors=remount-ro , data=ordered)
/dev/disk/by-uuid/5f3d0920-98a8-434a-9c02-8163dccf6c62 on/etc/hostname type Ext4 (Rw,relatime, errors=remount-ro,data=ordered)
/dev/disk/by-uuid/5f3d0920-98a8-434a-9c02-8163dccf6c62 on/etc/hosts type Ext4 (rw,relatime,errors=remount-ro,data=ordered)
...

Docker Run's-H can configure container hostname, which can be configured via-h hostname or--hostname=hostname, Docker writes hostname to/etc/hostname

For example:

xiaogang@ubuntu:~/shadowsocks$ sudo docker run-t-i--hostname Ubuu--rm

root@ubuu:/# Cat/etc/hostname
Ubuu

--link=conntainer_nameorid:alias, this option will add an alias to the/etc/hosts, point to Container_nameorid, without knowing the specific IP address, you can use the alias directly instead.

For example:

--dns=ip_address, a ip_address is added to the/ETC/RESOLV.CONF Server tab

--dns-search=domain, it'll be in/etc/. Resolv.conf's Search tab adds a domain, and if a example.com is added to the Search tab, host.example.com is also searched when container needs to find a host's IP.

The/etc/resolv.conf in the container is a copy of the/etc/resolv.conf from the host, except that the local nameserver of the host is filtered out, and if there is no nameserver after filtering, Docker will add Google's public nameserver,8.8.8.8 and 8.8.4.4 to Namerserver. Container modifications are notified when the host is resolv.conf modified

Communication between the container and the container and the outside

1. Need to set Ip_forward system parameters, must be set to 1

$ sysctl net.ipv4.conf.all.forwarding
net.ipv4.conf.all.forwarding = 0
$ sysctl net.ipv4.conf.all.forwarding =1
$ sysctl net.ipv4.conf.all.forwarding
net.ipv4.conf.all.forwarding = 1

2. Need to set up iptables to allow communication between them

Thank you for reading, I hope to help you, thank you for your support for this site!

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.