zoukankan      html  css  js  c++  java
  • Docker容器学习与分享07

    Docker容器网络

    分享06中学完了bridge网络,接着学习none网络host网络
    Docker在安装时会在host上默认创建三个网络,分别是bridgehostnull

    [root@promote ~]# docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    527281654b19        bridge              bridge              local
    9ab80c94885b        host                host                local
    c42335728d98        none                null                local
    

    none网络

    none网络就是什么网络都没有,就和一台没有联网的PC一样,可以在创建容器时通过--network=none指定。

    [root@promote ~]# docker run -it --name busybox --network none docker.io/busybox
    / # ifconfig
    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:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    

    创建完成后查看网络,发现只有一个回环设备,没有网卡设备(这里用的镜像是busybox,因为busybox包含了一些像ifconfig简单的命令,一开始我用的是centos镜像,后来发现centos镜像没有ifconfig命令,需要安装,而我创建的是无网络环境,所以就换成了busybox)。

    host网络

    host网络就是连接host网络的容器与主机共享网络,且网络配置一致。

    [root@promote ~]# docker run -it --name busybox --network host docker.io/busybox
    / # ifconfig
    docker0   Link encap:Ethernet  HWaddr 02:42:80:4B:97:72
              inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
              UP BROADCAST MULTICAST  MTU:1500  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:0
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    
    ens33     Link encap:Ethernet  HWaddr 00:0C:29:EB:2D:01
              inet addr:192.168.41.133  Bcast:192.168.41.255  Mask:255.255.255.0
              inet6 addr: fe80::4881:9be0:2bb6:62e/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:586 errors:0 dropped:0 overruns:0 frame:0
              TX packets:410 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:51651 (50.4 KiB)  TX bytes:46089 (45.0 KiB)
    
    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:68 errors:0 dropped:0 overruns:0 frame:0
              TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:6044 (5.9 KiB)  TX bytes:6044 (5.9 KiB)
    

    再来看一下主机的网络。

    [root@promote ~]# ifconfig
    docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
             inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
             ether 02:42:80:4b:97:72  txqueuelen 0  (Ethernet)
             RX packets 0  bytes 0 (0.0 B)
             RX errors 0  dropped 0  overruns 0  frame 0
             TX packets 0  bytes 0 (0.0 B)
             TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.41.133  netmask 255.255.255.0  broadcast 192.168.41.255
            inet6 fe80::4881:9be0:2bb6:62e  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:eb:2d:01  txqueuelen 1000  (Ethernet)
            RX packets 619  bytes 54111 (52.8 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 431  bytes 48129 (47.0 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 68  bytes 6044 (5.9 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 68  bytes 6044 (5.9 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

    可以发现他们是一致的。

  • 相关阅读:
    Mysql case when 根据数字排序 返回 string类型问题
    .NET Core 面试题
    一个人如何完成一整个网站的开发(推荐好文,看完绝对让你回味无穷)转载
    (转)实现C#中等价于的Javascript中的Math.Random()的函数,以得到一个随机数,double类型的,大于0小于1的,17位精度的
    brew安装指定版本的软件
    服务器被植入挖矿木马的心酸过程
    我把双系统的win10抹除了现在开机只按option还是会出现双系统选择,怎么把那个win10给取消了或删除掉
    java.lang.Exception: The server rejected the connection: None of the protocols were accepted
    Linux 技巧:让进程在后台可靠运行的几种方法
    jenkins backup and migration
  • 原文地址:https://www.cnblogs.com/Timesi/p/9292641.html
Copyright © 2011-2022 走看看