1. 程式人生 > >docker---橋接和container模式

docker---橋接和container模式

rep 共享 pipework bin body sysconfig etc 網絡 type

橋接模式(分配獨立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

  

  

docker---橋接和container模式