关于docker:43-Docker-bridge0详解

50次阅读

共计 2862 个字符,预计需要花费 8 分钟才能阅读完成。

查看虚拟机运行状态

为了演示更清晰直观,临时先移除了 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: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> 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

桥接网络示意图

正文完
 0