docker常见网络模式介绍
网络模式 | 简介 |
bridge | 为每一个容器分配、设置一个IP等,并将容器连接到一个docker0虚拟网桥,默认为该模式 |
host | 容器将不会虚拟出自己的网卡,配置自己的IP等,而是使用宿主机的IP和端口 |
none | 容器有独立的Network namespace,但并没有对其进行任何网络设置,如分配veth pair和网桥连接、IP等 |
container | 薪创建的容器不会创建自己的网卡和配置自己的Ip,而是和一个指定的容器共享Ip,端口范围 |
docker查看网络模式
docker network ls
Docker服务启动后默认会创建一个docker0网桥(其上有一个docker0内部接口),该桥接网络的名称为docker0,它在内核层连通了其他的物理或者虚拟网卡,这就将所有容器和本地主机都放到同一个物理网络,Docker默认指定了docker0接口的IP地址和子网掩码,让主机和容器之间可以通过网桥相互通信
查看bridge网络的详细信息
docker network inspect bridge
返回如下信息,其中"com.docker.network.bridge.name": "docker0", 则是默认定义的网络名称
[
{
"Name": "bridge",
"Id": "e14b2ec57f88e341c3e6a7eda02db45af39f82fbd8b5318aedc7bfe8ba023072",
"Created": "2022-03-06T20:07:19.4110786+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"0921d90e9dfd905208bac0db077671ea656b34760b87733441b1b62e7ff66bde": {
"Name": "tomcat",
"EndpointID": "a8b6b3e0b9ea34b5651d9b8163b376b14a101601fca2369aa2958fcdcab0bd00",
"MacAddress": "02:42:ac:11:00:04",
"IPv4Address": "172.17.0.4/16",
"IPv6Address": ""
},
"f0d483e2a98ad1264d8457dd7b325d9b9d5b8b1eb277ef95c8539399c374ed8f": {
"Name": "mysql",
"EndpointID": "593465db5ce707b3750e91f09fcbe4e18fd09e6ded55507d429dd9c428a4eee8",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
},
"f69d4bc0f458dc3bf4bcaa508de3a817817161f2512e525463d7398b1c769cf0": {
"Name": "zealous_fermat",
"EndpointID": "0b14ee0b9d4105fd0237f617906215982cd466e69ec46b8c12050720b738cd29",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]