操作环境

Centos7

Docker version 17.03.0-ce, build 60ccb22

操作说明

1.docker宿主机默认的network bridge为docker0,这里另外创建一个bridge:br0,使用物理服务器的em1网卡,配置如下:

[root@localhost network-scripts]# vi /etc/sysconfig/network-scripts/ifcfg-br0 
TYPE=Bridge
BOOTPROTO=static
DEVICE=br0
ONBOOT=yes
IPADDR=10.10.200.61
NETMASK=255.255.255.0
GATEWAY=10.10.200.254
DNS1=202.103.24.68
#DNS1=8.8.8.8

[root@localhost network-scripts]# vi ifcfg-em1
HWADDR=84:8F:69:DA:60:79
TYPE=Ethernet
BOOTPROTO=static
NAME=em1
UUID=0d9ef0b3-5514-41e7-8fa1-ace8f8c850c5
ONBOOT=yes
BRIDGE=br0

2.重启network

3.修改docker.server配置信息,添加--bridge参数,配置如下:

ExecStart=/usr/bin/dockerd --graph=/overlay --storage-driver=overlay --bridge=br0

4.重启daemon以及docker

#systemctl daemon-reload
#systemctl restart docker

5.新启动一个container,查看分配过来的IP

[root@localhost network-scripts]#  docker run -ti  ae5cb7280ec3      /bin/bash
[root@3a46b9fbd526 /]# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:0A:0A:C8:09  
          inet addr:10.10.200.9  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::42:aff:fe0a:c809/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:578 (578.0 b)  TX bytes:258 (258.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          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)

新启动的container与docker宿主机为同网段IP!




Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐