• docker 配置桥接网络


    2.5 docker配置桥接网络(上):
    
    
    为了使本地网络中的机器和Docker 容器更方便的通信,我们经常会有将Docker容器
    
    配置到和主机同一网段的需求。 这个需求其实很容器实现, 我们只需要将Docker容器个I
    
    和宿主机的网卡桥接起来,在给Docker容器配置IP就可以了。
    
    docker:/root# /sbin/ifconfig -a
    docker0   Link encap:Ethernet  HWaddr 82:1A:3F:70:76:A5  
              inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
              inet6 addr: fe80::dcbe:d9ff:fe62:d7e/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:7890 errors:0 dropped:0 overruns:0 frame:0
              TX packets:9934 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:404433 (394.9 KiB)  TX bytes:46463810 (44.3 MiB)
    
    eth2      Link encap:Ethernet  HWaddr 00:0C:29:6E:56:02  
              inet addr:192.168.32.151  Bcast:192.168.32.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe6e:5602/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:118661 errors:0 dropped:0 overruns:0 frame:0
              TX packets:13615 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:83659673 (79.7 MiB)  TX bytes:1304647 (1.2 MiB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:4 errors:0 dropped:0 overruns:0 frame:0
              TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:200 (200.0 b)  TX bytes:200 (200.0 b)
    
    veth02c9b44 Link encap:Ethernet  HWaddr DE:2C:35:EE:F2:46  
              inet6 addr: fe80::dc2c:35ff:feee:f246/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:2127 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2612 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:137978 (134.7 KiB)  TX bytes:10935963 (10.4 MiB)
    
    veth5e18f22 Link encap:Ethernet  HWaddr 82:1A:3F:70:76:A5  
              inet6 addr: fe80::801a:3fff:fe70:76a5/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:4798 errors:0 dropped:0 overruns:0 frame:0
              TX packets:6392 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:317572 (310.1 KiB)  TX bytes:27126952 (25.8 MiB)
    
    veth302ae23 Link encap:Ethernet  HWaddr 8E:35:47:57:27:1A  
              inet6 addr: fe80::8c35:47ff:fe57:271a/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:949 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1004 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:57991 (56.6 KiB)  TX bytes:8406459 (8.0 MiB)
    
    veth3818003 Link encap:Ethernet  HWaddr BA:E9:58:5C:09:57  
              inet6 addr: fe80::b8e9:58ff:fe5c:957/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:7 errors:0 dropped:0 overruns:0 frame:0
              TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:558 (558.0 b)  TX bytes:1226 (1.1 KiB)
    
    
    开启一个容器,都会生成一个 vethxx的网卡
    
    
    docker:/etc/sysconfig/network-scripts# pwd
    /etc/sysconfig/network-scripts
    
    
    cp ifcfg-etho ifcfg-br0
    
    
    配置:
    docker:/etc/sysconfig/network-scripts# cat ifcfg-eth0 
    DEVICE=eth2
    TYPE=Ethernet
    UUID=ac880d1b-2e37-425b-a58e-2a1e4625255c
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=none
    BRIDGE=br0
    #IPADDR=192.168.32.151
    #NETMASK=255.255.255.0
    #GATEWAY=192.168.32.254
    
    
    
    
    docker:/etc/sysconfig/network-scripts# cat ifcfg-bro 
    DEVICE=br0
    TYPE=Bridge
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=static
    IPADDR=192.168.32.151
    NETMASK=255.255.255.0
    GATEWAY=192.168.32.254
    
    
    
    docker:/etc/sysconfig/network-scripts# /sbin/ifconfig -a
    br0       Link encap:Ethernet  HWaddr 00:0C:29:6E:56:02  
              inet addr:192.168.32.151  Bcast:192.168.32.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe6e:5602/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:585 errors:0 dropped:0 overruns:0 frame:0
              TX packets:119 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:34193 (33.3 KiB)  TX bytes:14755 (14.4 KiB)
    
    docker0   Link encap:Ethernet  HWaddr 82:1A:3F:70:76:A5  
              inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
              inet6 addr: fe80::dcbe:d9ff:fe62:d7e/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:7890 errors:0 dropped:0 overruns:0 frame:0
              TX packets:9934 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:404433 (394.9 KiB)  TX bytes:46463810 (44.3 MiB)
    
    eth2      Link encap:Ethernet  HWaddr 00:0C:29:6E:56:02  
              inet6 addr: fe80::20c:29ff:fe6e:5602/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:588 errors:0 dropped:0 overruns:0 frame:0
              TX packets:125 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:42563 (41.5 KiB)  TX bytes:15263 (14.9 KiB)
    
    安装pipwork:
    
    git clone https://github.com/jpetazzo/pipework
    
    
    docker:/root# cp pipework/pipework /usr/local/bin/
    
    
    
    开启一个容器:
    
    docker run -itd --net=none --name centos_test01 centos bash
    
    
    rpm -Uvh https://repos.fedorapeople.org/openstack/EOL/openstack-grizzly/epel-6/iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm
    
    
    pipework bro 容器名  192.168.32.152/24@192.168.32.254 
    
    
    跟br0 同网段的IP
    
    
    
    
    
    
    
    
    
    
    
    

  • 相关阅读:
    docker安装部署命令
    kubernetes原理
    kubernetes安装部署
    Ansible安装
    模拟红绿灯(递归与队列)
    数据结构——顺序表
    数据结构——基本概念
    C语言高级编程
    Shell编程
    Shell命令
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6200285.html
Copyright © 2020-2023  润新知