删除默认的DOCKER0
ifconfig docker0 down
brctl delbr docker0
brctl show 查看删了没有
brctl addbr dok0
配置dok0的IP,并桥接到物理网卡 ens33上面,注意此时ens33物理网卡原有的网络连接将会断开
root@h1:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
#auto lo
#iface lo inet loopback
auto dok0
iface dok0 inet static
address 193.168.120.10
netmask 255.255.255.0
gateway 193.168.120.254
bridge_ports ens33
dns_nameservers 8.8.8.8
配置DOCKER使用DOK0并指定为容器分配的IP地址范围
root@h1:~# cat /etc/default/docker
DOCKER_OPTS="-b=docker_new1 --fixed-cidr='193.168.120.0/24'"
重启网络及DOCKER服务
/etc/init.d/networking restart
service docker restart
启动容器,再进入容器,IP分配到指定的网段,并能与外部通讯
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fce4c9aef4be python:2.7 "/bin/bash" 59 minutes ago Up 19 minutes modest_albattani
docker start fce4c9aef4be
docker attach fce4c9aef4be
再检查通讯情况
系统平台: Ubuntu 16.04 LTS
DOCKER版本:Docker version 1.13.1, build 092cba3