4.3 Docker bridge0详解

查看虚拟机运行状态

为了演示更清晰直观,暂时先移除了test2容器

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b567458c87c busybox "/bin/sh -c 'while t…" 14 minutes ago Up 14 minutes test1

查看虚拟机网络列表

ip a

1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/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_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:c9:c7:04 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
       valid_lft 73497sec preferred_lft 73497sec
    inet6 fe80::5054:ff:fec9:c704/64 scope link
       valid_lft forever preferred_lft forever
3: eth1:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:33:6b:20 brd ff:ff:ff:ff:ff:ff
    inet 192.168.205.10/24 brd 192.168.205.255 scope global noprefixroute eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe33:6b20/64 scope link
       valid_lft forever preferred_lft forever
4: docker0:  mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:95:c8:4d:58 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:95ff:fec8:4d58/64 scope link
       valid_lft forever preferred_lft forever
6: veth1a9acfd@if5:  mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether 06:ab:10:71:43:7c brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::4ab:10ff:fe71:437c/64 scope link
       valid_lft forever preferred_lft forever

查看容器网络列表

docker network ls

NETWORK ID NAME DRIVER SCOPE
f8ca7b41a380 bridge bridge local
efb6975c8935 host host local
3fa0f2e1a00b none null local

发现 NETWORK ID 为 f8ca7b41a380 的 DRIVER 就是 bridge 了。

查看特定网络涉及到的容器

使用docker network inspect f8ca7b41a380查看网络连接到的容器,说明test1连接了bridge网络

{
    "Containers": {
        "5b567458c87cc1c7eff73d47a753e1171c6478f2705868f01ebd858b196a2283": {
            "Name": "test1",
            "EndpointID": "f701cca45627ca1f4c23c2d7619465193127d61db71beefed4a6f09e94b164e1",
            "MacAddress": "02:42:ac:11:00:02",
            "IPv4Address": "172.17.0.2/16",
            "IPv6Address": ""
        }
    }
}

查看test1的ip列表

docker exec test1 ip a,说明容器test1是通过eth0@if6与虚拟主机的veth1a9acfd@if5这一pair,连接到虚拟机的docker0,从而实现网络互通的

1: lo:  mtu 65536 qdisc noqueue qlen 1000
    link/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_lft forever
5: eth0@if6:  mtu 1500 qdisc noqueue
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever

为了证明虚拟机上的 veth1a9acfd@if5 是连接到 docker0 的,我们可以yum install bridge-utils -y,然后使用brctl show命令即可发现veth1a9acfddocker0的一个接口

bridge name bridge id STP enabled interfaces
docker0 8000.024295c84d58 no veth1a9acfd

桥接网络示意图

4.3 Docker bridge0详解_第1张图片

你可能感兴趣的:(docker)