博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在 overlay 中运行容器 - 每天5分钟玩转 Docker 容器技术(51)
阅读量:4657 次
发布时间:2019-06-09

本文共 1133 字,大约阅读时间需要 3 分钟。

上一节我们创建了 overlay 网络 ov_net1,今天将运行一个 busybox 容器并连接到 ov_net1:

243.png

查看容器的网络配置:

bbox1 有两个网络接口 eth0 和 eth1。eth0 IP 为 10.0.0.2,连接的是 overlay 网络 ov_net1。eth1 IP 172.17.0.2,容器的默认路由是走 eth1,eth1 是哪儿来的呢?

其实,docker 会创建一个 bridge 网络 “docker_gwbridge”,为所有连接到 overlay 网络的容器提供访问外网的能力。

 docker network inspect docker_gwbridge 输出可确认 docker_gwbridge 的 IP 地址范围是 172.17.0.0/16,当前连接的容器就是 bbox1(172.17.0.2)。

 

docker network inspect docker_gwbridge

[

......

        "IPAM": {

            "Driver": "default",

            "Options": null,

            "Config": [

                {

                    "Subnet": "172.17.0.0/16",

                    "Gateway": "172.17.0.1"

                }

            ]

        },

        "Internal": false,

        "Attachable": false,

        "Containers": {

            "100dd1207eb8412a81c980dcd191d00eb4377a7a175a806a26038e8c12259766": {

                "Name": "gateway_100dd1207eb8",

                "EndpointID": "5077a2bfef80c695661f555412c3679b1a309cbba8a2f1a3247d6b414d35b819",

                "MacAddress": "02:42:ac:11:00:02",

                "IPv4Address": "172.17.0.2/16",

                "IPv6Address": ""

            }

        },

......

 

而且此网络的网关就是网桥 docker_gwbridge 的 IP 172.17.0.1。

这样容器 bbox1 就可以通过 docker_gwbridge 访问外网。

如果外网要访问容器,可通过主机端口映射,比如:

docker run -p 80:80 -d --net ov_net1 --name web1 httpd

验证完外网的连通性,下一节验证 overlay 网络跨主机通信。

二维码+指纹.png

转载于:https://www.cnblogs.com/CloudMan6/p/7294501.html

你可能感兴趣的文章
RabbitMQ的Vhost,Exchange,Queue原理分析
查看>>
Mac上编写C语言程序
查看>>
251.Flatten 2D Vector
查看>>
WLS Exception: Need to specify class name in environment or system property Solution
查看>>
人见人爱A^B
查看>>
消除头文件
查看>>
Android中数据文件解析(Json解析)
查看>>
自定义seekBar设置进度条背景图片
查看>>
java容器类1:Collection,List,ArrayList,LinkedList深入解读
查看>>
16日彻底去除安卓应用的内置广告
查看>>
再谈.NET Micro Framework移植
查看>>
ssm资源配置
查看>>
斗鱼爬虫,爬取颜值频道的主播图片和名字
查看>>
【Codeforces Round #439 (Div. 2) B】The Eternal Immortality
查看>>
【MemSQL Start[c]UP 3.0 - Round 1 B】 Lazy Security Guard
查看>>
【codeforces 499C】Crazy Town
查看>>
js 逻辑与 逻辑或
查看>>
“请求/响应”模型
查看>>
【坑】重写一个vector
查看>>
【UOJ 55】志愿者选拔
查看>>