1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
yum -y
install
bridge-utils
[root@linux-node2 ~]
# systemctl stop docker
[root@linux-node2 ~]
# ifconfig docker0 down
[root@linux-node2 ~]
# brctl delbr docker0
[root@linux-node2 network-scripts]
# cat ifcfg-br0
DEVICE=br0
ONBOOT=
yes
NM_CONTROLLED=no
BOOTPROTO=static
TYPE=Bridge
IPADDR=192.168.56.12
NETMASK=255.255.255.0
GATEWAY=192.168.56.2
[root@linux-node2 network-scripts]
# cat ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
IPV6INIT=no
NAME=eth0
DEVICE=eth0
ONBOOT=
yes
BRIDGE=br0
[root@linux-node2 network-scripts]
#
systemctl restart network
[root@linux-node2 network-scripts]
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link
/ether
00:0c:29:ac:7e:6d brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:feac:7e6d
/64
scope link
valid_lft forever preferred_lft forever
6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link
/ether
00:0c:29:ac:7e:6d brd ff:ff:ff:ff:ff:ff
inet 192.168.56.12
/24
brd 192.168.56.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feac:7e6d
/64
scope link
valid_lft forever preferred_lft forever
[root@linux-node2 network-scripts]
#
vi
/etc/sysconfig/docker
OPTIONS=
'--selinux-enabled --log-driver=journald --signature-verification=false -b=br0'
systemctl restart network
pipework的安装
wget https:
//github
.com
/jpetazzo/pipework/archive/master
.zip
unzip master.zip
cp
pipework-master
/pipework
/usr/local/bin/
chmod
+x
/usr/local/bin/pipework
这里最好不要让docker自动获取ip,下次启动会有变化而且自动获取的ip可能会和物理网段中的ip冲突
docker run -itd --net=none --name=
test
centos7
/bin/bash
为
test
容器设置一个与桥接物理网络同地址段的ip@网关
pipework br0
test
192.168.56.11
/24
@192.168.56.2
|
本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/2057465,如需转载请自行联系原作者