桥接模式(分配独立ip)
第一步:
修改网卡 cd /etc/sysconfig/network-scripts/ cp ifcfg-eth0 ifcfg-eth0.bak cp ifcfg-eth0 ifcfg-br0 vim ifcfg-eth0 DEVICE=eth0 HWADDR=00:0C:29:DB:B2:28 TYPE=Ethernet UUID=b2268aab-fa2e-49e9-bd67-2572f29e5790 ONBOOT=yes BRIDGE=br0 BOOTPROTO=none #IPADDR=192.168.1.179 #NETMASK=255.255.255.0 #GATEWAY=192.168.1.1 vim ifcfg-br0 DEVICE=br0 TYPE=Bridge ONBOOT=yes BOOTPROTO=static IPADDR=192.168.1.179 NETMASK=255.255.255.0 GATEWAY=192.168.1.1
第二步:
docker配置 pipework是一个Docker网络配置工具 git clone https://github.com/jpetazzo/pipework cp pipework/pipework /usr/local/bin/ 运行docker docker run -it --net=none --name test centos:6 /bin/bash 在宿主机上 rpm -Uvh https://repos.fedorapeople.org/openstack/EOL/openstack-grizzly/epel-6/iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm #给容器添加ip pipework br0 docker_name 192.168.1.187/24
container模式(容器共享一个ip)
docker run -i -t --net="container:02aac28b9234" mysql:latest /bin/bash