Docker Network Management – Configuring Bridging networks (CENTOS7)
To make it easier for machines and Docker containers in the local network to communicate, we often have the need to configure the Docker container to the same network segment as the host. This requirement is actually very easy to achieve, we just have to bridge the Docker container and the host's network card, and then the Docker container with IP on it.
* Install Pipwork #docker官方人员, a script written by Shell
git clone https://github.com/jpetazzo/pipework
CP ~/pipework/pipework/usr/local/bin/
No git command yum install git
* Open a container docker run-itd--net=none--name wyp123 Centos/bin/bash
Pipework br0 wyp123 172.7.15.201/[email protected] #201为容器的ip, the IP behind @ is the host IP, generating a network card.
Brctl addif br0 eth0 #eth0为宿主机网卡, this step is to connect the br0 and the Eth0 Bridge.
IP addr Add 172.7.15.107/24 br0 #把107的ip绑定在br0上
Docker exec-it Wyp123/bin/bash #进去后ifconfig查看就可以看到新添加的ip
Docker Network Management – Configuring Bridging networks (CENTOS6)
cd/etc/sysconfig/network-scripts/; CP Ifcfg-eth0 IFCFG-BR0
VI ifcfg-eth0//add Bridge=br0,bootproto=none, delete ipaddr,netmask,gateway,dns1
VI ifcfg-br0//Modify the device to Br0,type for Bridge, set the Eth0 network settings here
Service Network restart
Install Pipwork:
git clone https://github.com/jpetazzo/pipework;
CP ~/pipework/pipework/usr/local/bin/#为了方便执行命令 because the path is within $path
Open a container: Docker run-itd--net=none--name wyp123 Centos/bin/bash
Upgrade Package iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm, or you will get an error.
RPM-UVH https://repos.fedorapeople.org/openstack/EOL/openstack-grizzly/epel-6/ iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm #不安会报错Object "Netns" is unknown, try "IP Help"
Pipework Br0 wyp123 172.7.15.201/24 #配置IP
Docker exec-it Wyp123/bin/bash #进去后ifconfig查看就可以看到新添加的ip
2.5-docker Configuring Bridging Networks