Docker 网络 none模式

网友投稿 825 2022-10-18

Docker 网络 none模式

Docker 网络 none模式

处于none模式有自己的网卡,有网络模块但是docker不会给其配置IP地址,可以看到是没有ip的,需要手工配置IP地址。

none 网络就是什么都没有的网络。挂在这个网络下的容器除了 lo,没有其他任何网卡。容器创建时,可以通过 –network=none 指定使用 none 网络。

[root@localhost test]# docker run -itd --net=none centos-ssh3205a3b3ff63a7e568c5096fd20b1355fd758ed3f158011cbb10b96d3656cac8[root@localhost test]# docker exec -it 3205a3b3ff63 /bin/bash[root@3205a3b3ff63 ansible]# ifconfiglo: 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

要通过pipework配置IP,这工具要安装在宿主机上面。这个是有网卡模块的,只不过需要你来配置IP,这个企业用的多。

[root@localhost ~]# git clone into 'pipework'...remote: Enumerating objects: 8, done.remote: Counting objects: 100% (8/8), done.remote: Compressing objects: 100% (6/6), done.remote: Total 518 (delta 2), reused 5 (delta 2), pack-reused 510Receiving objects: 100% (518/518), 182.72 KiB | 17.00 KiB/s, done.Resolving deltas: 100% (272/272), done.[root@localhost ~]# lsanaconda-ks.cfg default.conf index.html pipework ROOT test[root@localhost ~]# cp pipework/pipework /usr/local/bin/

桥接网卡 容器的ID号 ip 掩码 网关[root@localhost ~]# pipework docker0 3205a3b3ff63 172.17.0.99/24@172.17.0.1 这样不需要dhcp分配,静态指定的[root@localhost ~]# docker exec -it 3205a3b3ff63 /bin/bash[root@3205a3b3ff63 ansible]# ifconfigeth1: flags=4163 mtu 1500 inet 172.17.0.99 netmask 255.255.255.0 broadcast 172.17.0.255 ether f6:04:29:d2:3c:4f txqueuelen 1000 (Ethernet) RX packets 8 bytes 648 (648.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1 bytes 42 (42.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

宿主机去ping一下

[root@3205a3b3ff63 ansible]# ping 172.17.0.99PING 172.17.0.99 (172.17.0.99) 56(84) bytes of data.64 bytes from 172.17.0.99: icmp_seq=1 ttl=64 time=0.034 ms^C--- 172.17.0.99 ping statistics ---1 packets transmitted, 1 received, 0% packet loss, time 0msrtt min/avg/max/mdev = 0.034/0.034/0.034/0.000 ms[root@3205a3b3ff63 ansible]# ping 172.17.0.1 PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.060 ms^C--- 172.17.0.1 ping statistics ---1 packets transmitted, 1 received, 0% packet loss, time 0msrtt min/avg/max/mdev = 0.060/0.060/0.060/0.000 ms[root@3205a3b3ff63 ansible]# ping baidu.comPING a.shifen.com (180.101.49.11) 56(84) bytes of data.64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=127 time=16.1 ms^C--- a.shifen.com ping statistics ---1 packets transmitted, 1 received, 0% packet loss, time 0msrtt min/avg/max/mdev = 16.169/16.169/16.169/0.000 ms使用使用pipework工具可以给虚拟机容器指定Ip地址,总结就是none模式有网络模块但没有给其配置ip

对于这样的一个封闭网络有什么用呢? 其实还真有应用场景。封闭意味着隔离,一些对安全性要求高并且不需要联网的应用可以使用 none 网络。比如某个容器的唯一用途是生成随机密码,就可以放到 none 网络中避免密码被窃取。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Kubernetes 内部DNS访问 Service
下一篇:MinUI 基于规范的小程序 UI 组件库,支持自定义标签组件,轻量、易用、工具化
相关文章

 发表评论

暂时没有评论,来抢沙发吧~