Docker学习(11) Docker 网络

2019-11-09  本文已影响0人  August________

Docker学习(11) Docker 网络

Docker网络简介

Docker网络——详解

基础理论

CNM

Libnetwork

驱动

单机桥接网络

lhf@lhf-virtual-machine:~$ docker network ls
NETWORK ID          NAME                             DRIVER              SCOPE
3c6fd32ed9fb        bridge                           bridge              local
8b95e29168fa        counter-app-master_counter-net   bridge              local
682a75797ba4        host                             host                local
596066e2fd78        none                             null                local

lhf@lhf-virtual-machine:~$ docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "3c6fd32ed9fbe215b5ee34a773ba14703ea7d0a295a3b54cd01906c3c2b749b6",
        "Created": "2019-11-08T21:51:18.740007297+08:00",
        "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,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.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": {}
    }
]

lhf@lhf-virtual-machine:~$ ip link show docker0
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 02:42:03:5f:82:17 brd ff:ff:ff:ff:ff:ff

lhf@lhf-virtual-machine:~$ docker network inspect bridge | grep bridge.name
            "com.docker.network.bridge.name": "docker0",
lhf@lhf-virtual-machine:~$ docker network create -d bridge localnet
2b5ed819e9331ffa5c109f5f81dc6080f18e78cee7fc8ad05df9455247c01a0b
lhf@lhf-virtual-machine:~$ docker network ls | grep localnet
2b5ed819e933        localnet                         bridge              local

lhf@lhf-virtual-machine:~$ brctl show
bridge name bridge id       STP enabled interfaces
br-2b5ed819e933     8000.02421d8b6570   no      
br-8b95e29168fa     8000.024223c21723   no      
docker0     8000.0242035f8217   no  
$ docker container run -d --name c1 \
> --network c1 \
> alpine sleep 1d

$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
f8bf6041757a        alpine              "sleep 1d"          46 seconds ago      Up 43 seconds                           c1


$ docker network inspect  localnet --format
"ConfigOnly": false,
        "Containers": {
            "f8bf6041757a51afc6b56d35a84a8370037d207230101c0df6fc565da1d68741": {
                "Name": "c1",
                "EndpointID": "7016a80031330e87c3073c1cd148a5bbef6aa39738cd84bcdfe1657cf19f214e",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

$ brctl show
bridge name bridge id       STP enabled interfaces
br-2b5ed819e933     8000.02421d8b6570   no      veth53c5236
br-8b95e29168fa     8000.024223c21723   no      
docker0     8000.0242035f8217   no      
$ docker container run -it --name c2 \
> --network localnet \
> alpine sh
/ # ping c1
PING c1 (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.296 ms
64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.143 ms
^C
--- c1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.143/0.219/0.296 ms
/ # 

端口映射

$ docker container run -d --name web \
> --network localnet \
> --publish 5000:80 \
> nginx

$ docker port web
80/tcp -> 0.0.0.0:5000

多机覆盖网络

接入现有网络

用于故障排查的容器和服务日志

$ docker container logs web
172.18.0.1 - - [08/Nov/2019:16:15:38 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0" "-"

服务发现

Ingress网络

docker网络——命令

上一篇 下一篇

猜你喜欢

热点阅读