Docker 之 四種網路模型 啤啤 笨笨

2022-09-22 23:27:24 字數 3322 閱讀 7072

一、nat(預設)nat網路模型,預設情況下,均為nat模式,如網路的埠對映就為nat二、none(無網路)格式:docker run --net=none

[root@docker ~]# docker run --rm -ti --net=none centos:centos7三、host(與主機相同ip)格式:docker run --net=host

[root@docker ~]# docker run --rm -ti --net=host centos:centos7

[root@docker /]# ifconfig

docker0: flags=4099 mtu 1500

inet 172.7.5.1 netmask 255.255.255.0 broadcast 172.7.5.255

inet6 fe80::42:28ff:fe56:8b6 prefixlen 64 scopeid 0x20

ether 02:42:28:56:08:b6 txqueuelen 0 (ethernet)

rx packets 135990 bytes 9017234 (8.5 mib)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 158771 bytes 317188403 (302.4 mib)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ens192: flags=4163 mtu 1500

inet 10.3.153.120 netmask 255.255.255.0 broadcast 10.3.153.255

inet6 fe80::36aa:b367:aa13:b475 prefixlen 64 scopeid 0x20

ether 00:50:56:9b:00:06 txqueuelen 1000 (ethernet)

rx packets 747539 bytes 528246025 (503.7 mib)

rx errors 0 dropped 1227 overruns 0 frame 0

tx packets 249250 bytes 38867074 (37.0 mib)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10

loop txqueuelen 1 (local loopback)

rx packets 0 bytes 0 (0.0 b)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 0 bytes 0 (0.0 b)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0四、聯合網路(即兩個容器共用乙個ip位址)第乙個容器執行

-----

[root@docker ~]# docker run --rm -ti centos:centos7 #以nat模式啟動了乙個容器

[root@2f504d6966dc /]# ifconfig

eth0: flags=4163 mtu 1500

inet 172.7.5.2 netmask 255.255.255.0 broadcast 172.7.5.255 #ip172.7.5.2

ether 02:42:ac:07:05:02 txqueuelen 0 (ethernet)

rx packets 7417 bytes 13726936 (13.0 mib)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 6118 bytes 473182 (462.0 kib)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

第二個容器執行,以聯合網路的方式

-----

格式:docker run —net=container:$

[root@docker ~]# docker ps #檢視第乙個容器的id值

container id image command created status ports names

2f504d6966dc centos:centos7 "/bin/bash" 6 minutes ago up 6 minutes thirsty_bhabha

[root@docker ~]# docker run --rm -ti --net=container:2f504d6966dc centos:centos7

[root@2f504d6966dc /]# ifconfig

eth0: flags=4163 mtu 1500

inet 172.7.5.2 netmask 255.255.255.0 broadcast 172.7.5.255

ether 02:42:ac:07:05:02 txqueuelen 0 (ethernet)

rx packets 15431 bytes 27381590 (26.1 mib)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 13359 bytes 1061065 (1.0 mib)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

loop txqueuelen 1 (local loopback)

rx packets 0 bytes 0 (0.0 b)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 0 bytes 0 (0.0 b)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Docker 四種網路模式

我們在使用docker run建立docker容器時,可以用 net選項指定容器的網路模式,docker有以下4種網路模式 host模式,使用 net host指定。container模式,使用 net container name or id指定。none模式,使用 net none指定。brid...

docker的四種網路模式

docker容器間通訊 實現原理 docker使用linux橋接,在宿主機虛擬乙個docker容器網橋 docker0 docker啟動乙個容器時會根據docker網橋的網段分配給容器乙個ip位址,稱為container ip,同時docker網橋是每個容器的預設閘道器。因為在同一宿主機內的容器都接...

docker四種模式

1 host模式 眾所周知,docker使用了linux的namespaces技術來進行資源隔離,如pid namespace隔離程序,mount namespace隔離檔案系統,network namespace隔離網路等。乙個network namespace提供了乙份獨立的網路環境,包括網絡卡...