删除网桥链接并绑定到新的网桥上
cloudtop@toplion:~$ sudo brctl delif docker0 veth8d3f1ef
cloudtop@toplion:~$ brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.0242f4f0f62b no
userbr 8000.3464a91e37bd no bond0
virbr0 8000.525400ded333 yes virbr0-nic
cloudtop@toplion:~$ sudo brctl addif userbr veth8d3f1ef
cloudtop@toplion:~$ brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.0242f4f0f62b no
userbr 8000.3464a91e37bd no bond0
veth8d3f1ef
virbr0 8000.525400ded333 yes virbr0-nic
cloudtop@toplion:~$ ifconfig | grep docker0
docker0 Link encap:Ethernet HWaddr 02:42:f4:f0:f6:2b
cloudtop@toplion:~$ ifconfig docker0 down
SIOCSIFFLAGS: Operation not permitted
cloudtop@toplion:~$ sudo !!
sudo ifconfig docker0 down
cloudtop@toplion:~$ ifconfig docker0 down
SIOCSIFFLAGS: Operation not permitted
cloudtop@toplion:~$ ifconfig | grep docker0
cloudtop@toplion:~$ brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.0242f4f0f62b no
userbr 8000.3464a91e37bd no bond0
veth8d3f1ef
virbr0 8000.525400ded333 yes virbr0-nic
配置默认网桥为自己新创建的网桥
cloudtop@toplion:~$ brctl addbr docker_new0
add bridge failed: Operation not permitted
cloudtop@toplion:~$ sudo brctl addbr docker_new0
cloudtop@toplion:~$ sudo ifconfig docker_new0 172.31.0.1 netmask 255.255.255.0
cloudtop@toplion:~$ sudo ifconfig | grep docker_new0
docker_new0 Link encap:Ethernet HWaddr de:78:69:dc:34:99
cloudtop@toplion:~$ su
Password:
root@toplion:/home/cloudtop# cd
root@toplion:~# echo 'DOCKER_OPTS="-b=docker_new0"' >> /etc/default/docker
root@toplion:~# service docker restart
root@toplion:~# ps -ef | grep docker
root 9840 1 1 09:57 ? 00:00:00 /usr/bin/dockerd --tlsverify --tlscacert=/home/cloudtop/ca.pem --tlscert=/home/cloudtop/server-cert.pem --tlskey=/home/cloudtop/server-key.pem -H=172.31.142.111:2376 -H=unix:///var/run/docker.sock
root 9851 9840 0 09:57 ? 00:00:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
root 10001 9536 0 09:57 pts/1 00:00:00 grep --color=auto docker
root@toplion:~# vim /etc/systemd/system/docker.service.d/docker.conf
root@toplion:~# systemctl daemon-reload
root@toplion:~# service docker restart
root@toplion:~# ps -ef | grep docker
root 11434 1 1 10:02 ? 00:00:00 /usr/bin/dockerd -b=docker_new0 --tlsverify --tlscacert=/home/cloudtop/ca.pem --tlscert=/home/cloudtop/server-cert.pem --tlskey=/home/cloudtop/server-key.pem -H=172.31.142.111:2376 -H=unix:///var/run/docker.sock
root 11445 11434 0 10:02 ? 00:00:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
root 11553 9536 0 10:02 pts/1 00:00:00 grep --color=auto docker
root@toplion:~# exit
创建容器测试
cloudtop@toplion:~$ docker run -itd ubuntu:14.04 /bin/bash
cloudtop@toplion:~$ brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.0242f4f0f62b no
docker_new0 8000.ca267b35699f no veth614b5fe
userbr 8000.3464a91e37bd no bond0
virbr0 8000.525400ded333 yes virbr0-nic
进入容器之后:
root@54967ebfb038:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:ac:1f:00:02
inet addr:172.31.0.2 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
版权声明:本文为u010324465原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。