您好,登錄后才能下訂單哦!
Docker容器有哪幾種網(wǎng)絡(luò)模型?針對(duì)這個(gè)問題,今天小編總結(jié)這篇有關(guān)Docker網(wǎng)絡(luò)模型的文章,希望能幫助更多想解決這個(gè)問題的朋友找到更加簡(jiǎn)單易行的辦法。
NAT網(wǎng)絡(luò)模型,默認(rèn)情況下,均為NAT模式,如網(wǎng)絡(luò)的端口映射就為NAT
格式:docker run --net=none
[root@docker ~]# docker run --rm -ti --net=none centos:centos7
格式:docker run --net=host
[root@docker ~]# docker run --rm -ti --net=Host centos:centos7
[root@docker /]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> 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<link>
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<UP,BROADCAST,RUNNING,MULTICAST> 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<link>
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<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
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
第一個(gè)容器運(yùn)行
-----[root@docker ~]# docker run --rm -ti centos:centos7 #以nat模式啟動(dòng)了一個(gè)容器 [root@2f504d6966dc /]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> 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 第二個(gè)容器運(yùn)行,以聯(lián)合網(wǎng)絡(luò)的方式 ----- 格式:Docker run —net=container:${container_id} [root@docker ~]# docker ps #查看第一個(gè)容器的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<UP,BROADCAST,RUNNING,MULTICAST> 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<UP,LOOPBACK,RUNNING> 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
看完上述內(nèi)容,你們對(duì)Docker網(wǎng)絡(luò)模型有進(jìn)一步的了解嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。