Docker 1 12新功能探索(9) network基础

docker1.12中的network功能作了一定改进, 但是关于network应该如何使用,docker中的网络模型是如何设计的,当我们在run起来一个container而全然没有意识到network的时候,docker是怎样处理的,在这篇文章中,我们回去尝试一探究竟.

docker1.12有关network的特性增加

特性
Built-in Virtual-IP based internal and ingress load-balancing using IPVS
Routing Mesh using ingress overlay network
Secured multi-host overlay networking using encrypted control-plane and Data-plane
MacVlan driver is out of experimental
Add driver filter to network ls
Adding network filter to docker ps –filter
Add –link-local-ip flag to create, run and network connect to specify a container’s link-local address
Add network label filter support
Removed dependency on external KV-Store for Overlay networking in Swarm-Mode
Add container’s short-id as default network alias
run options –dns and –net=host are no longer mutually exclusive
Fix DNS issue when renaming containers with generated names
Allow both network inspect -f {{.Id}} and network inspect -f {{.ID}} to address inconsistency with inspect output

比如关于:Add driver filter to network ls。现在可以使用driver作为过滤条件来确认network的情况

[root@host31 ~]# docker network ls --filter driver=bridge
NETWORK ID          NAME                DRIVER              SCOPE
e2836311817e        bridge              bridge              local
[root@host31 ~]#
  • 1
  • 2
  • 3
  • 4

docker network的种类

在刚刚安装完docker之后,下面三个network是被自动地创建出来的。

network种类
none
host
bridge
[root@host31 ~]# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
e2836311817e        bridge              bridge              local
58211460fd1f        host                host                local
a157ec9146b7        none                null                local
[root@host31 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

初期状态

使用network inspect命令可以看到以上三种network最初的状态。

docker network inspect none

[root@host31 ~]# docker network inspect none
[
    {
        "Name": "none",
        "Id": "a157ec9146b720cb38981fa1a22390b60c78fcd4396a1d50d979427f480799d6",
        "Scope": "local",
        "Driver": "null",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": []
        },
        "Internal": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
[root@host31 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

docker network inspect host

[root@host31 ~]# docker network inspect host
[
    {
        "Name": "host",
        "Id": "58211460fd1f3da1bbc392a43ddd2b79a8bec663620b7783cefcf910940ddcd9",
        "Scope": "local",
        "Driver": "host",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": []
        },
        "Internal": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
[root@host31 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

docker network inspect bridge

[root@host31 ~]# docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "e2836311817eabd7b2d28e3bbc2ae5e7a545a8652446d52ca77cd55fa7ba50d1",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]
[root@host31 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

创建一个container加入none

用一下命令可以创建一个centos的container将其加入none的network中。

docker run -it --name container_none --network=none centos /bin/bash
  • 1
[root@host31 ~]# docker run -it --name container_none --network=none centos /bin/bash
[root@0dfd0712c5ca /]#
  • 1
  • 2

另外打开一个终端,让我们来看看发生了什么

[root@host31 tmp]# docker network inspect none
[
    {
        "Name": "none",
        "Id": "a157ec9146b720cb38981fa1a22390b60c78fcd4396a1d50d979427f480799d6",
        "Scope": "local",
        "Driver": "null",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": []
        },
        "Internal": false,
        "Containers": {
            "0dfd0712c5cab81f3328a39aa5f57723c957915b67d5bc235fb514120bd03f56": {
                "Name": "container_none",
                "EndpointID": "a7b8a817f1cf42fa3566eb0327b337d2352f0f8efa5ceec4d10f96b69e13ffc4",
                "MacAddress": "",
                "IPv4Address": "",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]
[root@host31 tmp]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

加入了none的network的container,我们可以从上面通过他的Name等发现就是刚刚穿件的container_none,下面我们来看一下这个container中有哪些特点。

[root@0dfd0712c5ca /]# ping www.baidu.com
ping: unknown host www.baidu.com
[root@0dfd0712c5ca /]#
[root@0dfd0712c5ca /]# ping 192.168.32.31
connect: Network is unreachable
[root@0dfd0712c5ca /]#
[root@0dfd0712c5ca /]# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.338 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.082 ms
^C
--- localhost ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.082/0.210/0.338/0.128 ms
[root@0dfd0712c5ca /]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

除了自己谁都连接不通,是它的特点。

创建一个container加入host

用一下命令可以创建一个centos的container将其加入host的network中。

docker run -it --name container_host --network=host centos /bin/bash
  • 1
[root@host31 ~]# docker run -it --name container_host --network=host centos /bin/bash
[root@host31 /]#
  • 1
  • 2

怎么回事,不是-i方式启动的麽,另外怎么目录变了呢。另外打开一个终端,让我们来看看发生了什么

[root@host31 tmp]# docker ps |grep container_host
43b4f08151e2        centos              "/bin/bash"         7 minutes ago       Up 6 minutes                            container_host
[root@host31 tmp]#
这个就是host的方式的container,上面提示的[root@host31 /]已经不是在宿主机,而是在container_host中了,我们可以简单的确认一下,比如至少用centos官方最新镜像启动的container中是不可能有我们安装的docker1.12的。
[root@host31 /]# hostname
host31
[root@host31 /]# docker info
bash: docker: command not found
[root@host31 /]#
虽然你的hostname跟宿主机一样,但是我们都知道那是你的马甲了。通过下面的inspect也能看到其已经加入host网络中了。
[root@host31 tmp]# docker network inspect host
[
    {
        "Name": "host",
        "Id": "58211460fd1f3da1bbc392a43ddd2b79a8bec663620b7783cefcf910940ddcd9",
        "Scope": "local",
        "Driver": "host",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": []
        },
        "Internal": false,
        "Containers": {
            "43b4f08151e2da050e26aa62b27f68229cd112a963a35e5fcb7b6ed47e0e7f11": {
                "Name": "container_host",
                "EndpointID": "365f5858203d3d5162edf7350fa1094174df29f60d9978f90aa975068f93db74",
                "MacAddress": "",
                "IPv4Address": "",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]
[root@host31 tmp]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

加入了host的network的container,我们可以从上面通过他的Name等发现就是刚刚穿件的container_host,下面我们来看一下这个container中有哪些特点。

[[email protected] /]# ping -w1 www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=1 ttl=128 time=61.2 ms

--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 61.262/61.262/61.262/0.000 ms
[[email protected] /]#
[[email protected] /]# ping container_host
ping: unknown host container_host
[[email protected] /]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

跟none不同,它不再是只能自己跟自己通信. 它和外部是连通的。

创建一个container加入bridge

用一下命令可以创建一个centos的container将其加入bridge的network中。因为缺省不指定就是这种方式, 我们平时没有意识到network的存在,其实是使用的bridge的方式

docker run -it --name container_bridge centos /bin/bash
  • 1

[[email protected] ~]# docker run -it –name container_bridge centos /bin/bash

[[email protected] /]#

  • 1

另外打开一个终端,让我们来看看发生了什么

[root@host31 tmp]# docker ps |grep container_bridge
743d5689399a        centos              "/bin/bash"         42 seconds ago      Up 41 seconds                           container_bridge
[root@host31 tmp]# docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "e2836311817eabd7b2d28e3bbc2ae5e7a545a8652446d52ca77cd55fa7ba50d1",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Containers": {
            "743d5689399aab527f83a0708763970bc671801ff377ac791f9aee2b58de4b34": {
                "Name": "container_bridge",
                "EndpointID": "c0ad0de740ed65b7c6e8e63fc34e42e807c9d82822341bef8f474dcca8fc4272",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]
[root@host31 tmp]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

加入了bridge的network的container,我们可以从上面通过他的Name等发现就是刚刚穿件的container_bridge,下面我们来看一下这个container中有哪些特点。

[root@743d5689399a /]# ping -w1 www.baidu.com
PING www.a.shifen.com (103.235.46.39) 56(84) bytes of data.
64 bytes from 103.235.46.39: icmp_seq=1 ttl=127 time=255 ms

--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 255.315/255.315/255.315/0.000 ms
[root@743d5689399a /]#
[root@743d5689399a /]# ping container_bridge
ping: unknown host container_bridge
[root@743d5689399a /]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

跟none不同,它不再是只能自己跟自己通信.它和外部是连通的。在接下来的文章中,我们将会通过更多的试验来学习docker不同的network是如何运转以及他们之间可以如何通信等。

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://www.cnblogs.com/captainbed

原文地址:https://www.cnblogs.com/firsttry/p/10232309.html

时间: 2024-12-09 19:13:56

Docker 1 12新功能探索(9) network基础的相关文章

Docker 1 12新功能探索(7) 服务编排三剑客简单总结

docker内置编排功能和目前成熟的编排工具相比可能还略显弱势,但是毕竟它是docker原生态的工具,占有地利的得天独厚的优势.同时目前内置swarm/node/service"三剑客"所组成的组合也能对普通的编排和应用场景提供足够的支持.本文将对docker1.12中这三小件进行简单总结. docker swarm 操作 详细说明 init 初期化集群 join 以node(worker)或者manager的身份加入集群 join-token 管理join-token update

Docker 1 12新功能探索(8) Remote Api 1 24

Docker的Remote Api并不是1.12才有的,Docker1.12的Remote Api升到了1.24.Remote api的使用在1.12中没有大的变化,稍微大一点的变化是到这个版本之后,二进制文件分裂成了主client的docker以及主server的dockerd了.在centos上通过systemd的配置变化不大,无非是将tcp://ip:port设定到启动的Option中而已,下面来看一下如何设定和简单使用. 事前确认 可以看到只有unix socket的方式 [[email

Docker 1 12新功能探索(4) 1分钟创建集群

在这篇文章里面我们将会通过创建一个极其简单的3个节点的集群来学习一下docker swarm 模式的使用方法.这个1.12版本中最引人关注的部分到底使用的感觉如何.因为没有在大型的生产环境中进行严格的比较,单从研究性质或者小规模的集群的创建的感觉来说和kubernetes的集群创建不相上下,使用方便,在准备妥当的情况下,手速快的朋友1分钟之内完全能够创建完毕. 事前确认 [[email protected] ~]# docker info |egrep 'Manager|Version' WAR

Windows Server 2016 新功能HCI(超融合基础架构) By S2D

超融合基础架构(Hyper-Converged Infrastructure,或简称"HCI")也被称为超融合架构,是指在同一套单元设备(x86服务器)中不仅仅具备计算.网络.存储和服务器虚拟化等资源和技术,而且还包括缓存加速.重复数据删除.在线数据压缩.备份软件.快照技术等元素,而多节点可以通过网络聚合起来,实现模块化的无缝横向扩展(scale-out),形成统一的资源池.超融合架构(Hyperconvergence Infrastructure, HCI)将虚拟化计算和存储整合到同

XenApp/XenDesktop 7.12新功能LHC解读

在今天,Citrix发布了期待已久的XenApp/XenDesktop新版本7.12,在7.12中有许多值得期待的新功能(访问Citrix edocs查看7.12文档).其中,本文将在此处解读新功能:Local Host Cache,简称LHC,中文名为本地主机缓存.虽然我们中的许多人都熟悉XenApp 6.5中的LHC功能,但那是基于IMA管理架构下的LHC.作为FMA管理架构下的LHC,和IMA管理架构下的LHC是不同的架构,下面我们就来说说这些关于LHC的内容. 一.IMA架构简述 IMA

TFS 2015 Update 2功能探索

微软刚刚发布了TFS 2015 update 2的测试包,https://blogs.msdn.microsoft.com/bharry/2016/02/10/team-foundation-server-2015-update-2-rc-1-is-available/. 相对Update 1,这次更新包含了很多用户期待的功能,作者第一时间下载更新了自己的系统,并与大家分享经验. 1. 升级TFS 2015.1到Update 2 Update 2的安装过程与之前的版本一样,安装过程非常简单,加载

Windows 10 20H1 2004新功能

Windows 10的年度更新版本20H1即将问世. 目前可以从insider preview渠道中获得.这个版本中看上去对搜索功能做了不小的改进.包括搜索的磁盘占用率以及搜索的一些展示方式. 其它的一些改进包括 Windows Subsystem for Linux的改进 https://www.cnblogs.com/qishine/p/12430933.html DirectX 12新功能预览 安全模式中支持Windows Hello的数字密码 支持网络摄像机 支持自动重启UWP程序 Xb

Docker 1.12.0将要发布的新功能

导读 按计划,6/14 是1.12.0版本的 feature冻结 的日子,再有两个星期Docker 1.12.0也该发布了.这里列出来的新功能,都是已经合并到主分支的功能,不出意外,下一个版本的Docker应该是能体验到了. 下周2016 DockerCon也该开始了,好像也有一场专门来讲Docker新特性的,不过在这之前,我们就可以抢先一步,浏览一下这些新功能.新特性.尤其是前两个,都是比较吸引人的功能. Swarmkit集成 前几天Docker刚刚发布了 Swarmkit ,也就是Swarm

docker 1.12 版本 的新特性

(1)docker swarm:集群管理,子命令有init, join, leave, update (2)docker service:服务创建,子命令有create, inspect, update, remove, tasks (3)docker node:节点管理,子命令有accept, promote, demote, inspect, update, tasks, ls, rm (4)docker stack/deploy:试验特性,用于多应用部署, 类似与 docker-compo