[root@docker2 ~]# docker network create --subnet=10.10.10.0/24 docker1 #新键网桥docker1
42323044a4f88a8766d9367e150b9f630cf61f2dd2d9f2d81fad1dc787edac68
[root@docker2 ~]# ifconfig #使用ifconfig查看网卡名称,发现不是docker1,而是以br开头的字符串
br-42323044a4f8: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 10.10.10.1 netmask 255.255.255.0 broadcast 0.0.0.0
ether 02:42:e3:1f:eb:b6 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
我们可以通过如下几步修改网卡名称:
1.[root@docker2 ~]# docker network list
NETWORK ID NAME DRIVER SCOPE
20d5d1508381 bridge bridge local
42323044a4f8 docker1 bridge local
2b94069ca87d host host local
5eccab8d02af none null local
2.查看系统默认docker0(20d5d1508381)的底层信息
[root@docker2 ~]# docker netwrok inspect 20d5d1508381
......
}
},
"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": {}
}
]
3. 删除网桥
[root@docker2 ~]# docker network rm docker1
docker1
4.重新创建网桥
[root@docker2 ~]# docker network create docker1 -o com.docker.network.bridge.name=docker1
bd9fb699dcda7f2fb8aaa3ed49d63e8ad6ffdbd0146f9fe991b50ecf4a32e8f9
5.使用ifconfig查看,可以看到网卡名称为docker1
[root@docker2 ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:3b:3d:b8:a1 txqueuelen 0 (Ethernet)
RX packets 41 bytes 3113 (3.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23 bytes 1650 (1.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:cf:ee:d3:6f 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
6.如果想在创建网桥的时候,自定网段,可执行如下命令:
[root@docker2 ~]# docker network create docker02 --subnet=172.30.0.0/16 -o com.docker.network.bridge.name=docker02
929023f79e25a03ed5fd99150ab354555ce5088bd90f4f1a06ed7a3be4cc4cde
[root@docker2 ~]# ifconfig docker02
docker02: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.30.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:61:44:57:54 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
结束.