4.2 Linux网络命名空间

在4.1环境搭建的基础上,进行如下实验

进入docker-node1虚拟机

vagrant ssh docker-node1

查看docker-node1虚拟机网络

使用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 75148sec preferred_lft 75148sec
    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
8: veth1b83279@if7:  mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether f2:a0:70:bf:e7:c2 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::f0a0:70ff:febf:e7c2/64 scope link
       valid_lft forever preferred_lft forever

在docker-node1上创建两个docker容器

docker pull busybox
docker run -d --name test1 busybox /bin/sh -c "while true;do sleep 3600;done"
docker run -d --name test2 busybox /bin/sh -c "while true;do sleep 3600;done"

使用docker ps查看虚拟机运行状态

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

查看容器网络

test1容器

docker exec test1 ip a
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

test2容器

docker exec test2 ip a
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
7: eth0@if8:  mtu 1500 qdisc noqueue
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever

ping测试,发现虚拟机与两台容器之间也是可以互相ping通的

ping 172.17.0.2
ping 172.17.0.3
docker exec test1 ping 172.17.0.1
docker exec test1 ping 172.17.0.3
docker exec test2 ping 172.17.0.1
docker exec test2 ping 172.17.0.2

你可能感兴趣的:(docker)