docker (centOS 7) 使用笔记3 - 修改docker默认的虚拟网址
近日在使用VPN时发现和docker的虚拟网址发生了冲突,都是172.17.0.1,故需要修改docker的默认网址。
1. 当前状态
# ifconfig docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0 ether 02:42:18:22:59:cd 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
2. 安装bridge网络工具
yum -y install bridge-utils
安装后,查看网桥列表
# brctl show bridge name bridge id STP enabled interfaces docker0 8000.0242182259cd no
3. 停止、删除网桥docker0
停止:
ip link set dev docker0 down
删除:
brctl delbr docker0
删除成功后,查看:
# brctl show bridge name bridge id STP enabled interfaces
4. 创建新的网桥
# brctl addbr bridge0
5. 设置网桥IP
ip addr add 192.168.0.1/24 dev bridge0
6. 启动网桥
ip link set dev bridge0 up
启动成功后,查看:
# brctl show bridge name bridge id STP enabled interfaces bridge0 8000.000000000000 no
# ifconfig bridge0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.1 netmask 255.255.255.0 broadcast 0.0.0.0 ether ca:ed:3e:52:f1:ee txqueuelen 1000 (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
7.修改docker启动设置
/etc/systemd/system/multi-user.target.wants/docker.service
ExecStart=/usr/bin/dockerd -b bridge0
添加选项 -b bridge0
8. 重启docker服务
systemctl daemon-reload
systemctl restart docker