docker 网络分析

一。 回顾之前的分享:

1. 远古时代的 运行方式

0

2. 虚拟化方式

0

3. 虚拟化技术

0

4.虚拟化技术和容器化技术区别

0

二。 docker网络

思考几个问题

1. docker如何和本地通讯的?

2. docker之前如何通讯的?

3. docker如何管理网段的?

4.docker如何持久化数据的?

0

2.通过veth pair 技术 放到ns1 和 ns2打通通讯

0

具体操作如下

[root@localhost ~]# ip netns exec ns1 ip a

1: lo: mtu 65536 qdisc noop state DOWN group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

[root@localhost ~]# ip netns exec ns1 ifup lo

[root@localhost ~]# ip netns exec ns1 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

[root@localhost ~]# ip netns add ns2

[root@localhost ~]# ip netns ls

ns2

ns1

[root@localhost ~]# ip link add veth-ns1 type veth peer name veth-ns2 生成pair

[root@localhost ~]# ip link

1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: ens192: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000

link/ether 00:0c:29:05:14:25 brd ff:ff:ff:ff:ff:ff

3: docker0: mtu 1500 qdisc noqueue state UP mode DEFAULT group default

link/ether 02:42:08:ad:c9:e8 brd ff:ff:ff:ff:ff:ff

8: br-871be8aa7492: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default

link/ether 02:42:46:95:d9:12 brd ff:ff:ff:ff:ff:ff

22: br-bccee08519bd: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default

link/ether 02:42:1e:52:32:c6 brd ff:ff:ff:ff:ff:ff

40: veth4170787@if39: mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default

link/ether 66:65:10:fc:ed:eb brd ff:ff:ff:ff:ff:ff link-netnsid 0

41: veth-ns2@veth-ns1: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

link/ether 22:e6:76:17:ed:23 brd ff:ff:ff:ff:ff:ff

42: veth-ns1@veth-ns2: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

link/ether a2:f3:a1:aa:8b:ec brd ff:ff:ff:ff:ff:ff

[root@localhost ~]# ip link set veth-ns1 netns ns1 把pair排队对应的ns

[root@localhost ~]# ip link set veth-ns2 netns ns2

[root@localhost ~]# ip link

1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: ens192: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000

link/ether 00:0c:29:05:14:25 brd ff:ff:ff:ff:ff:ff

3: docker0: mtu 1500 qdisc noqueue state UP mode DEFAULT group default

link/ether 02:42:08:ad:c9:e8 brd ff:ff:ff:ff:ff:ff

8: br-871be8aa7492: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default

link/ether 02:42:46:95:d9:12 brd ff:ff:ff:ff:ff:ff

22: br-bccee08519bd: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default

link/ether 02:42:1e:52:32:c6 brd ff:ff:ff:ff:ff:ff

40: veth4170787@if39: mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default

link/ether 66:65:10:fc:ed:eb brd ff:ff:ff:ff:ff:ff link-netnsid 0

[root@localhost ~]# ip netns exec ns1 ip link

1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

42: veth-ns1@if41: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

link/ether a2:f3:a1:aa:8b:ec brd ff:ff:ff:ff:ff:ff link-netnsid 1

[root@localhost ~]# ip netns exec ns2 ip link

1: lo: mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

41: veth-ns2@if42: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

link/ether 22:e6:76:17:ed:23 brd ff:ff:ff:ff:ff:ff link-netnsid 0

[root@localhost ~]# ip netns exec ns1 ip addr add 192.168.0.11/24 dev veth-ns1 网卡需要加入ip地址

[root@localhost ~]# ip netns exec ns2 ip addr add 192.168.0.12/24 dev veth-ns2

[root@localhost ~]# ip netns exec ns1 ip link

1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

42: veth-ns1@if41: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

link/ether a2:f3:a1:aa:8b:ec brd ff:ff:ff:ff:ff:ff link-netnsid 1

[root@localhost ~]# ip netns exec ns1 ip link set veth-ns1 up

[root@localhost ~]# ip netns exec ns2 ip link set veth-ns2 up

[root@localhost ~]# ip netns exec ns1 ip a 启动ns 执行了up操作后 才会ip

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

42: veth-ns1@if41: mtu 1500 qdisc noqueue state UP group default qlen 1000

link/ether a2:f3:a1:aa:8b:ec brd ff:ff:ff:ff:ff:ff link-netnsid 1

inet 192.168.0.11/24 scope global veth-ns1

valid_lft forever preferred_lft forever

inet6 fe80::a0f3:a1ff:feaa:8bec/64 scope link

valid_lft forever preferred_lft forever

[root@localhost ~]# ip netns exec ns2 ip a

1: lo: mtu 65536 qdisc noop state DOWN group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

41: veth-ns2@if42: mtu 1500 qdisc noqueue state UP group default qlen 1000

link/ether 22:e6:76:17:ed:23 brd ff:ff:ff:ff:ff:ff link-netnsid 0

inet 192.168.0.12/24 scope global veth-ns2

valid_lft forever preferred_lft forever

inet6 fe80::20e6:76ff:fe17:ed23/64 scope link

valid_lft forever preferred_lft forever

[root@localhost ~]# ip netns exec ns1 ping 192.168.0.12

PING 192.168.0.12 (192.168.0.12) 56(84) bytes of data.

64 bytes from 192.168.0.12: icmp_seq=1 ttl=64 time=0.080 ms

64 bytes from 192.168.0.12: icmp_seq=2 ttl=64 time=0.099 ms

2. docker container 和本地打通

0

3. docker 之前如何通讯

0

4.网络network

0

5. ip 地址不够, 可以增加network 来处理

6.让其他container 加入当前这个网络

docker network connect tomcat-net tomcat01

你可能感兴趣的:(docker 网络分析)