zoukankan      html  css  js  c++  java
  • pipework原理解析

    docker现有的网络模式比较简单,扩展性和灵活性都不能满足很多复杂应用场景的需求,很多时候用户需要自定义docker容器的网络,而非使用docke默认创建的IP和NAT规则。一个简单的做法就是将docker容器风络配置到本地主机网段中。

    将docker容器配置到本地网络环境中

    如果想使docker容器和容器主机处于同一网络,那么容器和主机应该处在一个二层网络中,能想到的场景就是把两台机器连在同一个交换机上,或者连在不同的级联交换机上,在虚拟机场景下,虚拟网桥可以将容器连在一个二层网络中,只要将主机的网卡桥接到虚拟网桥上,能将容器和主机的网络连接起来,构建完整拓扑结构后,只要再给docker容器分配一个局域网IP就大功告成了。

    安装pipework

    [root@localhost ~]# git clone https://github.com/jetazzo/pipework
    [root@localhost ~]# cp ~/pipework/pipework /usr/local/bin/

    完成对 test1的配置

    [root@localhost ~]# docker run -itd --name test1 --net=none busybox /bin/sh
    4effc4f5f1a1d85469834f34c6ae8817b8075b92cf2bde62d1ce9c61ab4275f8
    [root@localhost ~]# pipework br0 test1 10.10.103.95/24@10.10.103.254
    这一行配置命令执行的操作如下
    查看主机中是否存在bro网桥,不存在就创建
    向test1中加入一块名为eth1的网卡,并配置IP地址10.10.103.95/24
    若test1中已经有默认路由,则删掉,把10.10.103.254设为默认路由的网关
    将test1容器连接到之前创建的网桥bro上。
    [root@localhost ~]# docker attach 4effc4f5f1a1
    / # ifconfig
    eth1      Link encap:Ethernet  HWaddr DE:1D:FB:5E:DB:07  
              inet addr:10.10.103.95  Bcast:10.10.103.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:15 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:1206 (1.1 KiB)  TX bytes:42 (42.0 B)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1 
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    [root@localhost ~]# docker inspect --format='{{ .State.Pid }}' test1
    3242
    [root@localhost ~]# ln -s /proc/3242/ns/net /var/run/netns/3242
    [root@localhost ~]# ls -al /var/run/netns/3242
    lrwxrwxrwx. 1 root root 17 12月 28 21:05 /var/run/netns/3242 -> /proc/3242/ns/net
  • 相关阅读:
    远程连接redis服务
    redis的安装以及启动
    Easyui学习之右键菜单easyui-menu
    富文本编辑器KindEditor的使用
    zookeeper启动失败解决方法
    在TortoiseSVN使用clean up
    kettle性能优化
    idea快捷键
    Spring Cloud服务网关 Zuul Filter使用
    添加路由
  • 原文地址:https://www.cnblogs.com/liujunjun/p/12113084.html
Copyright © 2011-2022 走看看