Dcoker静态IP配置

作者: admin 分类: Docker,Linux 发布时间: 2018-07-09 14:26 浏览:972 次    

环境: centos7      br0      docker1.3

1、配置网络

  • 修改网卡配置
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
 [root@localhost network-scripts]# vim ifcfg-eno16777736

 TYPE=Ethernet
 BOOTPROTO=static
 DEFROUTE=yes
 PEERDNS=yes
 PEERROUTES=yes
 IPV4_FAILURE_FATAL=no
 NAME=eno16777736
 DEVICE=eno16777736
 ONBOOT=yes
 BRIDGE="br0"

注:删除配置中ip、netmask、gateway、dns,添加BRIDGE=”br0″

  • 添加br0设备
[root@localhost network-scripts]# vim ifcfg-br0

 TYPE="Bridge"
 BOOTPROTO=static
 DEFROUTE=yes
 PEERDNS=yes
 PEERROUTES=yes
 IPV4_FAILURE_FATAL=no
 IPADDR=172.20.10.7
 NETMASK=255.255.255.0
 GATEWAY=172.20.10.1
 DNS1=1.2.4.8
 DEVICE="br0"
 ONBOOT=yes

注:添加以上配置,把原网卡中ip、netmask、gateway、dns添加到br0设备

2、重启网络服务

[root@localhost ~]# systemctl restart network

3、查看当前网络配置

[root@localhost ~]#  ifconfig 

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
     inet 172.20.10.7 netmask 255.255.255.0 broadcast 172.20.10.255

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet6 fe80::20c:29ff:fe84:895a prefixlen 64 scopeid 0x20<link>
    ether 00:0c:29:84:89:5a txqueuelen 1000 (Ethernet)

4、安装pipework

[root@localhost ~]# yum -y install git
[root@localhost ~]# yum update -y nss curl libcurl
[root@localhost ~]# git clone  https://github.com/jpetazzo/pipework.git
[root@localhost ~]# cp /root/pipework/pipework /usr/local/bin/

5、创建容器

[root@localhost ~]# docker run -itd --network=none --name docker-test --privileged=true docker.io/centos bash

6、容器配置静态ip

语法:pipework <网桥名> <容器名/ID> ip/掩码@网关
[root@localhost ~]# pipework br0 docker-test 172.20.10.12/24@172.20.10.1

7、查看容器ip

[root@localhost ~]# docker exec -it docker-test bash
[root@f095ea31b8ce /]# yum -y install net-tools
[root@f095ea31b8ce /]# ifconfig 

 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
 inet 172.20.10.12 netmask 255.255.255.0 broadcast 172.20.10.255

 

 

 

 


温馨提示:如无特殊说明,本站文章均为作者原创,转载时请注明出处及相应链接!

发表评论