Esxi虚拟系统中虚拟机docker桥接网络
目的:实现容器和公司服务器同网段ip,公司服务器为esxi创建的虚拟机
注意:首先需要将公司esxi虚拟系统的主机网络设置为混杂模式
混杂模式:指一台机器能够接收所有经过它的数据流,而不论其目的地址是否是他
1. 登录VMWare vsphere client,找到主机配置中的网络,点击属性
2. 修改网络模式为混杂模式
centos6.5版本将docker容器配置局域网段
1、安装docker
[[email protected] ~]# rpm -ivh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[[email protected] ~]# rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[[email protected] ~]# yum -y install docker-io
[[email protected] ~]# yum installdevice-mapper-event-libs #防止启动docker时 死锁
[[email protected] ~]# service docker restart
[[email protected] ~]# service docker status
[[email protected] ~]# docker pull centos:6
[[email protected] ~]# ip link set dev docker0down #删除以前的网桥,docker0为你启动容器时候自动创建
[[email protected] ~]# brctl delbr docker0
[[email protected] ~]# cd/etc/sysconfig/network-scripts/
[[email protected] network-scripts]# vimifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:6D:DF:B8
TYPE=Ethernet
UUID=0b55c691-24ed-422d-bfbd-16bc03fecda4
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BRIDGE=br0
vim ifcfg-br0
DEVICE=br0
HWADDR=00:0C:29:6D:DF:B8
TYPE=Bridge
UUID=0b55c691-24ed-422d-bfbd-16bc03fecda4
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.1.104
GATEWAY=192.168.1.1
DNS=114.114.114.114
[[email protected] network-scripts]# servicenetwork restart
[[email protected] network-scripts]# unzippipework-master.zip
[[email protected] network-scripts]# cppipework-master/pipework /usr/local/bin/
[[email protected] network-scripts]# cd
#由于6版本中 iproute版本过低,后期分配IP给容器时会报错,所以需要升级
[[email protected] ~]# rpm -qa|grep iproute #当前iproute版本
iproute-2.6.32-31.el6.x86_64
[[email protected] ~]# yum install -yhttp://rdo.fedorapeople.org/rdo-release.rpm
[[email protected] ~]# vim/etc/yum.repos.d/rdo-release.repo
[openstack-queens]
name=OpenStack Queens Repository
baseurl=https://repos.fedorapeople.org/repos/openstack/EOL/openstack-icehouse/epel-6/
skip_if_unavailable=0
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-RDO-kilo
doc
[[email protected] ~]# yum repolist
[[email protected] ~]# yum install -y iproute
[[email protected] ~]# rpm -qa|grep iproute #升级后的iproute版本
iproute-2.6.32-130.el6ost.netns.2.x86_64
[[email protected] ~]# docker run -itd --net=none--name test centos:6 /bin/bash #运行容器
[[email protected] ~]# pipework br0 test192.168.1.104/[email protected]
[[email protected] ~]# docker exec -it test3/bin/bash
[[email protected] /]# ifconfig | head -5
eth1 Link encap:Ethernet HWaddrBE:1F:68:72:40:08
inet addr:192.168.1.104 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::bc1f:68ff:fe72:4008/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11266 errors:0 dropped:0 overruns:0 frame:0
[[email protected] /]# yum -y installiputils #安装ping命令软件包
[[email protected] /]# ping 192.168.1.1 #ping网关
PING 192.168.1.1 (192.168.1.1) 56(84) bytesof data.
64 bytes from 192.168.1.1: icmp_seq=1ttl=254 time=5.53 ms
[[email protected] /]# pingwww.baidu.com #到此完成
PING www.a.shifen.com (14.215.177.39)56(84) bytes of data.
64 bytes from 14.215.177.39: icmp_seq=1ttl=55 time=6.36 ms
64 bytes from 14.215.177.39: icmp_seq=2ttl=55 time=7.14 ms