docker自定义ip地址(自定义网桥)

2023-02-24 17:22:42 浏览数 (1)

如何修改docker0网桥的IP段

  • 关闭docker进程
代码语言:javascript复制
systemctl stop docker
  • 修改/etc/docker/daemon.json
代码语言:javascript复制
{ 
  "bip": "10.10.80.1/24" #改为需要的网段。
}

如果已经有/etc/docker/daemon.json文件,添加内容的时候就只需要添加大括号里面的内容就好了,不需要另外添加大括号。

  • 关闭docker0网桥
代码语言:javascript复制
ip link set dev docker0 down
  • 删除docker0网桥
代码语言:javascript复制
brctl delbr docker0
  • 重新加载docker的配置文件
代码语言:javascript复制
systemctl daemon-reload
  • 启动docker进程
代码语言:javascript复制
systemctl start docker
  • 查看docker0的网段
代码语言:javascript复制
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:cd:c4:39 brd ff:ff:ff:ff:ff:ff
    inet 172.16.8.16/24 brd 172.16.8.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fecd:c439/64 scope link 
       valid_lft forever preferred_lft forever
4: br-8c03afa71865: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:f0:b1:e4:fc brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global br-8c03afa71865
       valid_lft forever preferred_lft forever
92: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:a9:56:13:5d brd ff:ff:ff:ff:ff:ff
    inet 10.10.80.1/24 brd 10.10.80.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:a9ff:fe56:135d/64 scope link 
       valid_lft forever preferred_lft forever

0 人点赞