Docker 1.12 new function Exploration (TEN): Network Foundation

Source: Internet
Author: User
Tags docker ps docker run

This article will continue to study the network basics of Docker and will further understand how multiple container can communicate using network model and how to customize a network through a number of simple experiments. multiple container in none mode

Start two container join none

[Root@host31 ~]# Docker run-it--network=none centos/bin/bash
[root@a2a37d0ddc0b/]#
[Root@host31 ~]# Docker run-it--network=none centos/bin/bash
[Root@b8b7f66f1c12/]#

Confirmation of container after startup

[Root@host31 ~]# Docker PS
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
B8B7F66F1C12        CentOS              "/bin/bash"         seconds ago up      seconds                           Determined_visvesvaraya
a2a37d0ddc0b        centos              "/bin/bash"         seconds ago up      seconds                           Jovial_goldstine
[Root@host31 ~]#

Docker Network Inspect none confirm details

[Root@host31 ~]# Docker Network Inspect none [{' Name ': ' None ', ' Id ': ' a157ec9146b720cb38981fa1a22390
        B60c78fcd4396a1d50d979427f480799d6 ", Scope": "Local", "Driver": "null", "ENABLEIPV6": false, "IPAM": {"Driver": "Default", "Options": null, "Config": []}, "I 
                Nternal ": false," containers ": {" a2a37d0ddc0b5915422ce5ec5948ef715acfe84110abed11100373c4fc89c37a ": { "Name": "Jovial_goldstine", "EndpointId": "F0acf4f20f924a5fe5d6754fbfb61aa458e87500f02a56 4736c197fb7207f43d "," MacAddress ":" "," ipv4address ":" "," ipv6address ":"  '}, ' b8b7f66f1c12354fe784092697c93531d2966a0dee27ce301a558ba1dfd5b975 ': {' Name ': "Determined_visvesvaraya", "EndpointId": "91e7e7e1b1a5bfe7188be69baae53b01c181978094b2f19010b949fc6ebd152 7 "," MacAddress ":", "ipv4address": "", "ipv6address": ""}}, "Optio NS ': {}, ' Labels ': {}}] [Root@host31 ~]#

From the results of the inspect can be clearly seen ipv4address is not set, the basic should only Lo 127.0 0.1, so none of the mode of multiple container even in the same network can not communicate with each other. multiple container in host mode

Start two container to join host, host mode, the container and host share the network namespace, have the same network equipment as the host.

[Root@host31 ~]# Docker run-it--network=host--name host_container1 centos/bin/bash
[root@host31/]#
[Root@host31 ~]# Docker run-it--network=host--name host_container2 centos/bin/bash
[root@host31/]#

Confirmation of container after startup

[Root@host31 ~]# Docker PS
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
91223e0ce984        CentOS              "/bin/bash"         seconds ago up      seconds                           Host_container2
f7d361caf164        CentOS              "/bin/bash"         seconds ago up      seconds                           Host_container1
[ Root@host31 ~]#

Docker Network inspect host confirm details

[Root@host31 ~]# Docker Network Inspect host [{' Name ': ' Host ', ' Id ': ' 58211460fd1f3da1bbc392a43ddd2b
        79a8bec663620b7783cefcf910940ddcd9 ", Scope": "Local", "Driver": "Host", "ENABLEIPV6": false, "IPAM": {"Driver": "Default", "Options": null, "Config": []}, "I 
                Nternal ": false," containers ": {" 91223e0ce984105d5dfa24260148bc0dc9254c7211d0ca6e76faf54cd9d3c42f ": { "Name": "Host_container2", "EndpointId": "Bc0adbea4290527df3fe23d353a45ba324567de143d8b57 
            F2dc195046cdfeee1 "," MacAddress ":" "," ipv4address ":" "," ipv6address ":" " }, "f7d361caf164f67a3a5670dd9f2b826ccd2054c17989bf101a81b78480a69101": {"Name":
                "Host_container1", "EndpointId": "06e60004d1e0672fdf14dc775c10b5a2459867e7a1b760f338b769bd32811436", "MacAddress": "", "ipv4address": "", "ipv6address": ""}, "Options": {}, ' Labels ': {}}] [Root@host31 ~]#

Verify that all 2 container can connect to the extranet but cannot ping through the container name.

[Root@host31 ~]# Docker run-it--network=host--name host_container1 centos/bin/bash
[root@host31/]# Ping Host_cont Ainer1
Ping:unknown host Host_container1
[root@host31/]# ping host_container2
ping:unknown host Host_ Container2
[root@host31/]# ping-w1 www.baidu.com
ping www.a.shifen.com (14.215.177.37) bytes of data.< c6/>64 bytes from 14.215.177.37:icmp_seq=1 ttl=128 time=66.3 ms

---www.a.shifen.com ping statistics---
1 packet s transmitted, 1 received, 0% packet loss, time 0ms
RTT Min/avg/max/mdev = 66.304/66.304/66.304/0.000 ms
[Root@ho St31/]#
[Root@host31 ~]# Docker run-it--network=host--name host_container2 centos/bin/bash
[root@host31/]# Ping Host_cont Ainer2
Ping:unknown host Host_container2
[root@host31/]# ping host_container1
ping:unknown host Host_ Container1
[root@host31/]# ping-w1 www.baidu.com
ping www.a.shifen.com (61.135.169.121) bytes of data.< c6/>64 bytes from 61.135.169.121:icmp_seq=1 ttl=128 time=22.2 ms

---www.a.shifen.com ping statistics---
1 packe TS transmitted, 1 received, 0% packet loss, time 0ms
RTT Min/avg/max/mdev = 22.245/22.245/22.245/0.000 ms
[Root@h Ost31/]#
multiple container in bridge mode

Start two container join bridge

[Root@host31 ~]# Docker run-it--network=bridge--name bridge_container1 centos/bin/bash
[Root@5a55638c0ac2/]#
[Root@host31 ~]# Docker run-it--network=bridge--name bridge_container2 centos/bin/bash
[root@8e4621500007/]#

Confirmation of container after startup

[Root@host31 ~]# Docker PS
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
8e4621500007        CentOS              "/bin/bash"         wuyi seconds ago up       seconds                           Bridge_container2
5A55638C0AC2        CentOS              "/bin/bash" about         a minute ago up about   a minute                       bridge_container1
[Root@host31 ~]#

Docker Network inspect bridge confirm details

[Root@host31 ~]# Docker Network inspect bridge [{' Name ': ' Bridge ', ' Id ': ' 5da066475a0d5d0e54ba9e6f64 F80342eb188d0455b85a69b50bf222f13ce9a3 ", Scope": "Local", "Driver": "Bridge", "ENABLEIPV6": false
                , "IPAM": {"Driver": "Default", "Options": null, "Config": [
            {"Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1"} ]}, "Internal": false, "containers": {"5a55638c0ac2971e204668294ba3bb2d83487ef94f5a F506f83bef773d4fab64 ": {" Name ":" Bridge_container1 "," EndpointId ":" 63ee42bae5309639d1a51 2d8e4b7b81f3b8c83f454ca076bd5d8513ec637c88e "," MacAddress ":" 02:42:ac:11:00:02 "," ipv4addr ESS ":" 172.17.0.2/16 "," ipv6address ":" "}," 8e4621500007b357d69c417b5f7025258bb4e fc3f0c3076c3cff8d9ebb351A14 ": {" Name ":" Bridge_container2 "," EndpointId ":" 9f824c05d490e95c84a21684bd627a1005a146 4DCB74B8647E2AD31BE126CAFC "," MacAddress ":" 02:42:ac:11:00:03 "," ipv4address ":" 172.17.0.3 /16 "," ipv6address ":" "}}," Options ": {" Com.docker.network.brid Ge.default_bridge ": True", "COM.DOCKER.NETWORK.BRIDGE.ENABLE_ICC": "true", "com.docker.network.br Idge.enable_ip_masquerade ": True", "Com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com . Docker.network.bridge.name ":" Docker0 "," COM.DOCKER.NETWORK.DRIVER.MTU ":" 1500 "}," Labels ": {}}] [Root@host31 ~]#

By confirming, Bridge_container1 and Bridge_container2 are given the following IP

Container name IP
Bridge_container1 172.17.0.2
Bridge_container2 172.17.0.3

Verify that you can use IP to ping each other in addition to using the container name

[Root@host31 ~]# Docker run-it--network=bridge--name bridge_container1 centos/bin/bash [root@5a55638c0ac2/]# Ping Bri Dge_container1 Ping:unknown host Bridge_container1 [root@5a55638c0ac2/]# ping bridge_container2 ping:unknown host Bridg
E_container2 [root@5a55638c0ac2/]# ping-w1 172.17.0.2 ping 172.17.0.2 (172.17.0.2) bytes of data. Bytes from 172.17.0.2:icmp_seq=1 ttl=64 time=0.071 ms, bytes from 172.17.0.2:icmp_seq=2 ttl=64 time=0.074 ms---1 72.17.0.2 Ping Statistics---2 packets transmitted, 2 received, 0% packet loss, time 999ms rtt min/avg/max/mdev = 0.071/0
072/0.074/0.008 ms [Root@5a55638c0ac2/]# ping-w1 172.17.0.3 ping 172.17.0.3 (172.17.0.3) bytes of data. Bytes from 172.17.0.3:icmp_seq=1 ttl=64 time=0.178 ms---172.17.0.3 ping statistics---1 packets transmitted, 1 REC Eived, 0% packet loss, time 0ms rtt Min/avg/max/mdev = 0.178/0.178/0.178/0.000 ms [ROOT@5A55638C0AC2/]# PING-W1-Www.baid u.com PING www.a.shifen.com (14.215.177.38) 56 () bytes of data. Bytes from 14.215.177.38:icmp_seq=1 ttl=127 time=134 ms---www.a.shifen.com ping statistics---1 packets transmitte D, 1 received, 0% packet loss, time 0ms rtt Min/avg/max/mdev = 134.332/134.332/134.332/0.000 ms [ROOT@5A55638C0AC2/]#
[Root@host31 ~]# Docker run-it--network=bridge--name bridge_container2 centos/bin/bash [root@8e4621500007/]# Ping Bri Dge_container1 Ping:unknown host Bridge_container1 [root@8e4621500007/]# ping bridge_container2 ping:unknown host Bridg
E_container2 [root@8e4621500007/]# ping-w1 172.17.0.2 ping 172.17.0.2 (172.17.0.2) bytes of data. Bytes from 172.17.0.2:icmp_seq=1 ttl=64 time=0.121 ms---172.17.0.2 ping statistics---1 packets transmitted, 1 REC Eived, 0% packet loss, time 0ms rtt Min/avg/max/mdev = 0.121/0.121/0.121/0.000 ms [root@8e4621500007/]# PING-W1-172.17.0
.3 PING 172.17.0.3 (172.17.0.3) bytes of data. Bytes from 172.17.0.3:icmp_seq=1 ttl=64 time=0.072 ms---172.17.0.3 ping statistics---1 packets transmitted, 1 REC Eived, 0% packet loss, time 0ms rtt Min/avg/max/mdev = 0.072/0.072/0.072/0.000 ms [root@8e4621500007/]# PING-W1-Www.baid

u.com PING www.a.shifen.com (14.215.177.38) bytes of data. ---www.a.shifen.com ping statistics---
1 packets transmitted, 0 received, 100% packet loss, time 0ms [root@8e4621500007/]# 
user-defined network

User-defined networks can now create three kinds: Bridge/overlay/macvlan. This article mainly introduces the use of bridge to create a user-defined network, which is more widely used. A custom network consisting of three container will be created, as shown in the following figure.

Create a custom network

Command: Docker network Create–driver Bridge ISOLATED_NW

[Root@host31 ~]# Docker Network create--driver Bridge ISOLATED_NW
8c3cb606081806f7c23d26773a2acc30cc56b574fe0a2e720661e23781541a74

Confirm Results

[Root@host31 ~]# docker network ls |grep NW
8c3cb6060818        isolated_nw Bridge local
[root@host31 ~] #

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.