创建自定义的桥
-d指定bridge,指定ip是--subnet "172.25.100.0/24" 网关是 --gateway "172.25.100.1" 名称是linuxea0
使用--opt com.docker.network.bridge.name=linuxea0 linuxea0
指定名称网桥名称和网卡名称
如果你是compose。可以这样指定,参考官网网络页面
networks:
linuxea0:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.25.100.0/24
driver_opts:
com.docker.network.bridge.name: linuxea0
直接创建如下
[root@linuxea.com_10_10_240_145 ~]$ docker network create -d bridge --subnet "172.25.100.0/24" --gateway "172.25.100.1" --opt com.docker.network.bridge.name=linuxea0 linuxea0
d9bb0525cd4fe79912792b0014c89283c33d734de4bcac86ef59f72f7e9fa05e
查看
[root@linuxea.com_10_10_240_145 ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
55bd1d72865f bridge bridge local
52c6e8bc1257 host host local
5641646f87c0 linuxea0 bridge local
39e5f4c19ea3 none null local
此时就多了一个br-5641646f87c0,ip就是这个地址的网关
[root@linuxea.com_10_10_240_145 ~]$ ip a|grep linuxea
106: linuxea0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
inet 172.25.100.1/24 brd 172.25.100.255 scope global linuxea0
此刻就可以创建容器加入到此网络
[root@linuxea.com_10_10_240_145 ~]$ docker run --name linuxea -it --network linuxea0 --rm busybox
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
107: eth0@if108: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:ac:19:64:02 brd ff:ff:ff:ff:ff:ff
inet 172.25.100.2/24 brd 172.25.100.255 scope global eth0
valid_lft forever preferred_lft forever