Docker:容器的四种网络类型 [十三]
一、None类型
简介:不为容器配置任何网络功能,--net=none
1、创建容器
docker run -it --network none busubox:latest
2、功能测试
[root@luoahong ~]# docker run -it --network none busybox:latest
/ # ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) / # free -m
total used free shared buff/cache available
Mem: 1984 730 125 0 1128 1135
Swap: 2047 0 2047
/ # ping www.baidu.com
ping: bad address 'www.baidu.com'
/ # ping ls
ping: bad address 'ls'
测试小结:
1、网卡只有一块io
2、只能执行本地命令,无法使用ping,ls
3、网络类型查看
[root@luoahong ~]# docker inspect 148da827024a
[
{
"Id": "148da827024a7e250d58684fedbd7467b1ec1950aa2f87f8f4c64f0094af905c",
"Created": "2019-01-18T07:34:16.468365453Z",
"Path": "sh",
"Args": [],
"State": {
..........
"MacAddress": "",
"Networks": {
"none": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "03062097926d6dfd6b1296295154c960f7e7989a106f7a1cb318c1040e4fa327",
"EndpointID": "cfb8a5eb16445bd8bb32708848a481c4638b86927e08fef4151e987e440869ec",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
二、Container
简介:与另一个运行中的容器共享Network Namespace,--net=container:containerID
docker run -it --network container:name centos:6.9
netstat -lntup #是因为另外一个容器使用了80端口 共享网络端口不能冲突
ps -ef
docker ps -a
docker inspect ID #信息全是空 ping 172.168.0.2 yum install tcpdump -y
tcpdump -i eth0 icmp
共享网络端口不能冲突
三、Host
简介:与主机共享Network Namespace,--net=host
1、创建容器
[root@luoahong ~]# docker run -it --network host centos:6.9
2、功能测试
1、容器命令测试
[root@luoahong /]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 :::22 :::* LISTEN -
tcp 0 0 :::32769 :::* LISTEN -
tcp 0 0 :::32770 :::* LISTEN -
tcp 0 0 :::32771 :::* LISTEN -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
udp 0 0 0.0.0.0:3255 0.0.0.0:* -
udp 0 0 127.0.0.1:323 0.0.0.0:* -
udp 0 0 :::28221 :::* -
udp 0 0 ::1:323 :::* -
[root@luoahong /]# hostname
luoahong
[root@luoahong /]# ifconfig
br-ad2616372f01 Link encap:Ethernet HWaddr 02:42:14:4D:EC:B9
inet addr:172.18.0.1 Bcast:172.18.255.255 Mask:255.255.0.0
inet6 addr: fe80::42:14ff:fe4d:ecb9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3772 errors:0 dropped:0 overruns:0 frame:0
TX packets:4439 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2284090 (2.1 MiB) TX bytes:4238472 (4.0 MiB) docker0 Link encap:Ethernet HWaddr 02:42:F7:2F:D6:20
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
inet6 addr: fe80::42:f7ff:fe2f:d620/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:648 (648.0 b) eth0 Link encap:Ethernet HWaddr 00:0C:29:E7:B9:46
inet addr:192.168.231.136 Bcast:192.168.231.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee7:b946/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:203307 errors:0 dropped:0 overruns:0 frame:0
TX packets:88428 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:289713694 (276.2 MiB) TX bytes:7698693 (7.3 MiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) vethac33a3b Link encap:Ethernet HWaddr F2:9B:3D:42:9E:B4
inet6 addr: fe80::f09b:3dff:fe42:9eb4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1871 errors:0 dropped:0 overruns:0 frame:0
TX packets:2128 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1161525 (1.1 MiB) TX bytes:1283465 (1.2 MiB) vethc0fae95 Link encap:Ethernet HWaddr EE:A2:D7:DD:0E:4C
inet6 addr: fe80::eca2:d7ff:fedd:e4c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:21 errors:0 dropped:0 overruns:0 frame:0
TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:26497 (25.8 KiB) TX bytes:3284 (3.2 KiB) veth43c45fd Link encap:Ethernet HWaddr FA:06:6C:F7:4E:94
inet6 addr: fe80::f806:6cff:fef7:4e94/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:1296 (1.2 KiB) veth68aaa11 Link encap:Ethernet HWaddr 3A:A1:00:65:05:AC
inet6 addr: fe80::38a1:ff:fe65:5ac/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:23 errors:0 dropped:0 overruns:0 frame:0
TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:26610 (25.9 KiB) TX bytes:3415 (3.3 KiB) vethc477df7 Link encap:Ethernet HWaddr AA:CF:39:D8:B3:0E
inet6 addr: fe80::a8cf:39ff:fed8:b30e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3772 errors:0 dropped:0 overruns:0 frame:0
TX packets:4439 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2284090 (2.1 MiB) TX bytes:4238472 (4.0 MiB)
2、宿主机命令测试
[root@luoahong ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1166/sshd
tcp6 0 0 :::22 :::* LISTEN 1166/sshd
tcp6 0 0 :::32769 :::* LISTEN 2629/docker-proxy
tcp6 0 0 :::32770 :::* LISTEN 2871/docker-proxy
tcp6 0 0 :::32771 :::* LISTEN 2884/docker-proxy
udp 0 0 0.0.0.0:68 0.0.0.0:* 1110/dhclient
udp 0 0 0.0.0.0:3255 0.0.0.0:* 1110/dhclient
udp 0 0 127.0.0.1:323 0.0.0.0:* 648/chronyd
udp6 0 0 :::28221 :::* 1110/dhclient
udp6 0 0 ::1:323 :::* 648/chronyd
[root@luoahong ~]# hostname
luoahong
[root@luoahong ~]# ifconfig
br-ad2616372f01: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 172.18.255.255
inet6 fe80::42:14ff:fe4d:ecb9 prefixlen 64 scopeid 0x20<link>
ether 02:42:14:4d:ec:b9 txqueuelen 0 (Ethernet)
RX packets 3772 bytes 2284090 (2.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4439 bytes 4238472 (4.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:f7ff:fe2f:d620 prefixlen 64 scopeid 0x20<link>
ether 02:42:f7:2f:d6:20 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 648 (648.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.231.136 netmask 255.255.255.0 broadcast 192.168.231.255
inet6 fe80::20c:29ff:fee7:b946 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:e7:b9:46 txqueuelen 1000 (Ethernet)
RX packets 203331 bytes 289715676 (276.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 88441 bytes 7705439 (7.3 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 veth43c45fd: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::f806:6cff:fef7:4e94 prefixlen 64 scopeid 0x20<link>
ether fa:06:6c:f7:4e:94 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 1296 (1.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 veth68aaa11: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::38a1:ff:fe65:5ac prefixlen 64 scopeid 0x20<link>
ether 3a:a1:00:65:05:ac txqueuelen 0 (Ethernet)
RX packets 23 bytes 26610 (25.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 37 bytes 3415 (3.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vethac33a3b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::f09b:3dff:fe42:9eb4 prefixlen 64 scopeid 0x20<link>
ether f2:9b:3d:42:9e:b4 txqueuelen 0 (Ethernet)
RX packets 1871 bytes 1161525 (1.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2128 bytes 1283465 (1.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vethc0fae95: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::eca2:d7ff:fedd:e4c prefixlen 64 scopeid 0x20<link>
ether ee:a2:d7:dd:0e:4c txqueuelen 0 (Ethernet)
RX packets 21 bytes 26497 (25.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 34 bytes 3284 (3.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vethc477df7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::a8cf:39ff:fed8:b30e prefixlen 64 scopeid 0x20<link>
ether aa:cf:39:d8:b3:0e txqueuelen 0 (Ethernet)
RX packets 3772 bytes 2284090 (2.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4439 bytes 4238472 (4.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
测试小结:
1、主机名和宿主机是一样
2、netstat -lntup的结果也是一样
3、ifconfig也是一样,几乎和宿主机分辨不清楚
4、但是容器看不到主机的程序
3、网络类型查看
"MacAddress": "",
"Networks": {
"host": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "30b37ec09ff25e54c6b8208779335bfe7b01729fc830db0c2c70434ca6817eb2",
"EndpointID": "94f41095acd2ba3d85210cc3667fc6e4324d3cacb9c1243a0747b4e46774a811",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
四、Bridge
简介:Docker设计的NAT网络模型
1、创建容器
docker run -d httpd:latest
2、功能测试
[root@luoahong ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:1a:8d:3d:28 txqueuelen 0 (Ethernet)
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 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.228.135 netmask 255.255.255.0 broadcast 192.168.228.255
inet6 fe80::20c:29ff:fe66:d93a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:66:d9:3a txqueuelen 1000 (Ethernet)
RX packets 235 bytes 25094 (24.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 206 bytes 28905 (28.2 KiB)
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
测试小结:docker0就是nat网络,不用过多解释
3、网络类型查看
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "d766f2526542a828e4b6e302fcc592a1a945bce83df236b9f24efbbea3eff4f4",
"EndpointID": "b2f80a78210a384f6ec5a8acc7f502d55f0858470f04e279a091aadc1912e82d",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
Docker:容器的四种网络类型 [十三]的更多相关文章
- Docker学习第四天(Docker四种网络模式)
Docker四种网络模式 实现原理 Docker使用Linux桥接(参考<Linux虚拟网络技术>),在宿主机虚拟一个Docker容器网桥(docker0),Docker启动一个容器时会根 ...
- [docker]docker的四种网络方式
声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 内容系本人学习.研究和总结,如有雷同,实属荣幸! bridge方式(默认) H ...
- [转帖]Docker四种网络模式
Docker(十四)-Docker四种网络模式 https://www.cnblogs.com/zhuochong/p/10069293.html 计算机网络相关的知识 非常有用.. Docker 安 ...
- Docker——四种网络模式
docker run创建Docker容器时,可以用–net选项指定容器的网络模式,Docker有以下4种网络模式: bridge模式:使用–net =bridge指定,默认设置: host模式 ...
- Docker 四种网络模式
原文 https://www.cnblogs.com/gispathfinder/p/5871043.html 我们在使用docker run创建Docker容器时,可以用--net选项指定容器的网络 ...
- 进入Docker容器的4种方式
进入Docker容器的4种方式 在使用Docker创建了容器之后,大家比较关心的就是如何进入该容器了,其实进入Docker容器有好几多种方式,这里我们就讲一下常用的几种进入Docker容器的方法. 进 ...
- 快速理解VirtualBox的四种网络连接方式
VirtualBox中有4中网络连接方式: NAT Bridged Adapter Internal Host-only Adapter VMWare中有三种,其实他跟VMWare 的网络连接方式都是 ...
- 普通java类加入spring容器的四种方式
今天在自己开发的工具类中使用了spring注入的方式调用了其他类,但是发生的报错,在整理了后今天小结一下. 首先简单介绍下spring容器,spring容器是整个spring框架的核心,通常我们说的s ...
- JDBC 学习笔记(二)—— 详解 JDBC 的四种驱动类型
JDBC 有四种驱动类型,分别是: JDBC-ODBC 桥(JDBC-ODBC bridge driver plus ODBC driver) 本地 API 驱动(Native-API partly ...
随机推荐
- Go 语言笔记
Go 语言笔记 基本概念 综述 Go 语言将静态语言的安全性和高效性与动态语言的易开发性进行有机结合,达到完美平衡. 设计者通过 goroutine 这种轻量级线程的概念来实现这个目标,然后通过 ch ...
- ATL右键文件菜单
自己写的小程序中用到的,网上资料相对还是毕竟全的,这里再整理下.毕竟我也不是很了解ATL,里面估计还是有不少问题的,就当作参考吧. 1.创建ATL工程,这个没什么好讲的. 我对COM组件没什么研究,这 ...
- 虚拟机 与 host主机,无法ping通的问题
这个写的比较简单,先做以下记录 centos虚拟机安装到别的电脑上,因为linux中的程序需要向外有网络互通,所以需要重新设置ip 通过 ifconfig eth4 192.168.0.20 bro ...
- 【导航】Python相关
[博客导航] Python相关导航 [索引]Python常用资源(从新手到大牛) [任务]Python语言程序设计.MOOC学习 [笔记]Python集成开发环境——PyCharm 2018.3下载. ...
- 英语口语练习系列-C15-心情不好
单词 1. artist [ˈɑ:tɪst] n. 艺术家 a great artist 一名伟大的艺术家 a Chinese artist 一名中国艺术家 2. beef [bi:f] n. 牛肉 ...
- DB2批量插入性能对比
import ibm_db import random import time first_names = '赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏' \ '陶姜戚谢邹喻柏水窦章 ...
- 2019年桌面Linux需要做好的7件事
2019年桌面Linux需要做好的7件事 新的一年已经到来,这意味着又一年过去了,Linux还是没有发现自己主宰了桌面.Linux在许多方面做得非常好,在接下来的几周,我们将研究一些最适合您各种需求的 ...
- 【题解】P2324 [SCOI2005]骑士精神
·有关IDA* 是带有估值函数的迭代加深搜索,表现出出色的效率. 估值函数可以简单的定义为「已经到位的骑士的个数」. 然后就是普通的迭代加深了. 算法酷炫不一定赢,搜索好才是成功. ——Loli Co ...
- 25 python 初学(socket,socketserver)
参考blog :www.cnblogs.com/yuanchenqi/articles/5692716.html 1. sk = socket.socket() 里面有两个重要的参数,family 和 ...
- TNS-12535/12606 and ORA-3136 on Connection to Database (Doc ID 2313573.1)
今天遇到一问题 telnet 都是通的,但是两台数据库服务器还是无法 sqlplus 连接 ,最后发现 两台服务器的 mtu 值不同,其中一台为 1500 一台为9000, 以前只是认为 telnet ...