1. 程式人生 > >用PIPEWORK為docker容器配置獨立IP

用PIPEWORK為docker容器配置獨立IP

官方網站:https://github.com/jpetazzo/pipework
宿主環境:centos7


安裝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 


給宿主機建立網橋
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 
TYPE=Ethernet
#BOOTPROTO=static
#IPADDR=172.16.146.116
#NETMASK=255.255.255.0
#GATEWAY=172.16.146.1
#DNS1=8.8.8.8
#DNS2=192.168.252.3
BOOTPROTO="none"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
NAME=eno16777736
ONBOOT=yes
BRIDGE="br0"
~


設定物理網絡卡橋接到網橋
[
[email protected]
~]# vi /etc/sysconfig/network-scripts/ifcfg-br0 
TYPE="Bridge"
BOOTPROTO=static
IPADDR=172.16.146.116
NETMASK=255.255.255.0
GATEWAY=172.16.146.1
PREFIX=24
DNS1=8.8.8.8
DNS2=192.168.252.3
NAME=br0
ONBOOT=yes
DEVICE=br0


執行一個容器:
[[email protected] ~]# pipework br0 $(docker run -d -it -p 80:80 --name testduliip centos) 172.16.146.113/
[email protected]

再執行一個:
[[email protected] ~]# pipework br0 $(docker run -d -it --net=none --name testduliip01 centos) 172.16.146.112/[email protected]


重啟容器後需要再次指定:
pipework br0 testduliip  172.16.146.113/[email protected]
pipework br0 testduliip01  172.16.146.112/[email protected]