docker--container之间的link,bridge create
container的name和ID一样,也是唯一的,当不知道container的IP时,可以用name替代,但需要先配置link
下面创建两个container 时,未配置link所以ping name 不通。
[root@localhost ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f81ab807503c busybox "/bin/sh -c 'while t…" hours ago Up hours test2
cba625871070 busybox "/bin/sh -c 'while t…" hours ago Up hours test1
[root@localhost ~]# docker exec test1 ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu qdisc noqueue
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/ brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@localhost ~]# docker exec test2 ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
: eth0@if21: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu qdisc noqueue
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff
inet 172.17.0.3/ brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@localhost ~]# docker exec test1 ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3): data bytes
bytes from 172.17.0.3: seq= ttl= time=0.074 ms
bytes from 172.17.0.3: seq= ttl= time=0.114 ms
^C
[root@localhost ~]# docker exec test1 ping test2 ^C
[root@localhost ~]# docker exec test2 ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2): data bytes
bytes from 172.17.0.2: seq= ttl= time=0.077 ms
bytes from 172.17.0.2: seq= ttl= time=0.100 ms
^C
[root@localhost ~]# docker exec test2 ping test1 ^C
[root@localhost ~]#
把test2删了重下创建,并指定link,link具有单向性
[root@localhost ~]# docker stop test2
test2
[root@localhost ~]# docker rm test2
test2
[root@localhost ~]#
[root@localhost ~]# docker run --name test2 -d --link test1 busybox /bin/sh -c "while true;do sleep 3600;done"
WARNING: IPv4 forwarding is disabled. Networking will not work.
68789fa4dc47ce821337c64898c11693e24dcc47ff06641e89feabd9a7ffe21d
[root@localhost ~]# docker exec test2 ping test1
PING test1 (172.17.0.2): data bytes
bytes from 172.17.0.2: seq= ttl= time=0.073 ms
bytes from 172.17.0.2: seq= ttl= time=0.071 ms
bytes from 172.17.0.2: seq= ttl= time=0.071 ms
^C
[root@localhost ~]# docker exec test1 ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu qdisc noqueue
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/ brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@localhost ~]# docker exec test2 ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2): data bytes
bytes from 172.17.0.2: seq= ttl= time=0.076 ms
bytes from 172.17.0.2: seq= ttl= time=0.161 ms
^C
[root@localhost ~]# docker exec test2 ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
: eth0@if23: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu qdisc noqueue
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff
inet 172.17.0.3/ brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@localhost ~]# docker exec test1 ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3): data bytes
bytes from 172.17.0.3: seq= ttl= time=0.087 ms
bytes from 172.17.0.3: seq= ttl= time=0.085 ms
^C
[root@localhost ~]# docker exec test1 ping test2 ^C
[root@localhost ~]#
创建bridge
[root@localhost ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
4e8172ef8e01 bridge bridge local
9e8c9ce3e33b host host local
6d01f937585b none null local
[root@localhost ~]# docker network create -d bridge my-bridge
b190bd600feb9ab1293e882b4b5c5b828ab4dda1215fd25e9a1921ac8e2f2f07
[root@localhost ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
4e8172ef8e01 bridge bridge local
9e8c9ce3e33b host host local
b190bd600feb my-bridge bridge local
6d01f937585b none null local
[root@localhost ~]#
create container 并指定docker network
[root@localhost ~]# brctl show #br-b190bd600feb即刚才create的my-bridge
bridge name bridge id STP enabled interfaces
br-b190bd600feb .0242e6e2a884 no
docker0 .0242e850c76c no veth59c00fa
vethfdefc77
virbr0 .525400105abe yes virbr0-nic
[root@localhost ~]# docker run -d --name test3 --network my-bridge busybox /bin/sh -c "while true;do sleep 3600;done" #增加network参数
WARNING: IPv4 forwarding is disabled. Networking will not work.
cec10f0cd32dc6c059bf29173572a34d0d41c2ff5602d0b8ccac0032a4ac2911
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br-b190bd600feb .0242e6e2a884 no veth75fc0ca
docker0 .0242e850c76c no veth59c00fa
vethfdefc77
virbr0 .525400105abe yes virbr0-nic
[root@localhost ~]#
再create container 网络连接my-bridge
[root@localhost ~]# docker run -d --name test4 --network my-bridge busybox /bin/sh -c "while true;do sleep 3600;done"
WARNING: IPv4 forwarding is disabled. Networking will not work.
19216c85489ee71d68bff33ff1ce64a6aff4f035e91659acd08ec9349e3440f3
[root@localhost ~]# docker network inspect my-bridge
[
{
"Name": "my-bridge",
"Id": "b190bd600feb9ab1293e882b4b5c5b828ab4dda1215fd25e9a1921ac8e2f2f07",
"Created": "2019-07-18T20:11:48.739837987-07:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"19216c85489ee71d68bff33ff1ce64a6aff4f035e91659acd08ec9349e3440f3": {
"Name": "test4",
"EndpointID": "9411999854b328be4ad2362a38967f770635bfda8cbf34190e0a61fad83bd815",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
},
"cec10f0cd32dc6c059bf29173572a34d0d41c2ff5602d0b8ccac0032a4ac2911": {
"Name": "test3",
"EndpointID": "e6470a84504340d4668c0c66b6c4d068898ac9c177e0caf51d8869198349f84a",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
[root@localhost ~]#
同个bridge同网段,能ping通,不同bridge不同网段,不能ping通
[root@localhost ~]# docker exec test3 ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
: eth0@if26: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu qdisc noqueue
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff
inet 172.18.0.2/ brd 172.18.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@localhost ~]# docker exec test4 ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
: eth0@if28: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu qdisc noqueue
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff
inet 172.18.0.3/ brd 172.18.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@localhost ~]# docker exec test3 ping 172.18.0.3
PING 172.18.0.3 (172.18.0.3): data bytes
bytes from 172.18.0.3: seq= ttl= time=0.077 ms
bytes from 172.18.0.3: seq= ttl= time=0.138 ms
^C
[root@localhost ~]#
[root@localhost ~]# docker exec test3 ping 172.17.0.3 ^C
[root@localhost ~]#
如果container是在用户自定义的bridge上,则默认是link的
[root@localhost ~]# docker exec test3 ping test4
PING test4 (172.18.0.3): data bytes
bytes from 172.18.0.3: seq= ttl= time=0.042 ms
bytes from 172.18.0.3: seq= ttl= time=0.149 ms
^C
[root@localhost ~]# docker exec test4 ping test3
PING test3 (172.18.0.2): data bytes
bytes from 172.18.0.2: seq= ttl= time=0.060 ms
bytes from 172.18.0.2: seq= ttl= time=0.065 ms
^C
[root@localhost ~]#
如果把别的bridge也连接到用户创建的bridge上,那也是默认link上的
[root@localhost ~]# docker network connect my-bridge test1
[root@localhost ~]# docker network inspect
bridge host my-bridge none
[root@localhost ~]# docker network inspect my-bridge
[
{
"Name": "my-bridge",
"Id": "b190bd600feb9ab1293e882b4b5c5b828ab4dda1215fd25e9a1921ac8e2f2f07",
"Created": "2019-07-18T20:11:48.739837987-07:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"19216c85489ee71d68bff33ff1ce64a6aff4f035e91659acd08ec9349e3440f3": {
"Name": "test4",
"EndpointID": "9411999854b328be4ad2362a38967f770635bfda8cbf34190e0a61fad83bd815",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
},
"cba62587107007983d45a4383598dbec18a37d33e415f2325572e8f98f36a32a": {
"Name": "test1",
"EndpointID": "2b5c94ee7d8f5c76ae531e023190528e16cf18f3291298610f3b601511130c32",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
},
"cec10f0cd32dc6c059bf29173572a34d0d41c2ff5602d0b8ccac0032a4ac2911": {
"Name": "test3",
"EndpointID": "e6470a84504340d4668c0c66b6c4d068898ac9c177e0caf51d8869198349f84a",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
[root@localhost ~]# docker exec test4 ping test1
PING test1 (172.18.0.4): data bytes
bytes from 172.18.0.4: seq= ttl= time=0.082 ms
bytes from 172.18.0.4: seq= ttl= time=0.170 ms
^C
[root@localhost ~]#
docker--container之间的link,bridge create的更多相关文章
- 分布式高级(十三)Docker Container之间的数据共享
sudo docker run -it -v /usr/lib:/usr/lib/dbdata --name dbcontainer-192.168.1.184 ubuntu:14.04 sudo d ...
- docker images之间相互通信 link
同一个host上的两个container 首先启动一个nginx. container起名叫netease_nginx docker run --detach --name netease_nginx ...
- bridge br0 docker 网络问题 Docker Container与Docker Host
Docker学习笔记:Docker 网络配置 - docker ppt - docker中文社区http://www.docker.org.cn/dockerppt/111.html Bridge t ...
- docker container(容器)
docker 容器 Docker容器类似于一个轻量级的沙箱,Docker利用容器来运行和隔离应用 容器是从镜像创建的应用运行实例.它可以启动,开始,停止,删除,而这些容器都是彼此相互隔离,互不可见的. ...
- Docker源码分析(八):Docker Container网络(下)
1.Docker Client配置容器网络模式 Docker目前支持4种网络模式,分别是bridge.host.container.none,Docker开发者可以根据自己的需求来确定最适合自己应用场 ...
- Docker container network configuration
http://xmodulo.com/networking-between-docker-containers.html How to set up networking between Docker ...
- Docker: docker container常用命令实战(2)-数据持久化
应用服务是在容器中运行的,容器随时会被删除,如果是个mysql容器呢?数据存储在容器里,容器删除了,数据也没了,那就是个噩梦. 所以一些数据是需要存储在容器之外的,可以是宿主机,可以是网络存储位置上, ...
- Docker: docker container常用命令实战
容器管理,容器常用选项 选项 描述 -i, –interactive 交互式 -t, –tty 分配一个伪终端 -d, –detach 运行容器到后台 -e, –env 设置环境变量 -p, –pub ...
- Docker源码分析(七):Docker Container网络 (上)
1.前言(什么是Docker Container) 如今,Docker技术大行其道,大家在尝试以及玩转Docker的同时,肯定离不开一个概念,那就是“容器”或者“Docker Container”.那 ...
随机推荐
- 【问题解决方案】GitHub仓库重构之将某个或某些文件夹移动到其他文件夹内
仓库重构时遇到的问题,在GitHub页面里好像没有类似的操作按钮? 搜了一下好像要用到一些命令比如rm等,但是我对Linux类的命令不是很熟悉 于是想试试曲线救国,先把远程库的文件pull到本地,在本 ...
- 07.Linux-CentOS系统库文件libaudit.so.1丢失问题
问题:缺少共享库文件sudo: error while loading shared libraries: libaudit.so.1: cannot open shared object file: ...
- Vue组件-组件组合
组件设计初衷就是要配合使用的,最常见的就是形成父子组件的关系:组件 A 在它的模板中使用了组件 B. <html> <head> <title>Vue组件 A 在它 ...
- Echarts 折线类型
1:Echarts2.0 这种皮肤下柱状图转折线图默认是平滑曲线 默认皮肤为硬折线: 如果需要在2.0的macarons皮肤下使用硬折线需显式设置以下属性: series: [ { ...
- ERROR=(CODE=1153)
jdbc 连接oracle数据库(10.2.0.4),应用程序报错如下: Connection refused(DESCRIPTION=(ERR=1153)(VSNNUM=169870592)(ERR ...
- 【串线篇】Mybatis拓展之MBG
MBG-逆向工程 一.介绍 MBG:MyBatis Generator:代码生成器: MyBatis官方提供的代码生成器:帮我们逆向生成: 正向: table----javaBean---BookDa ...
- 数组之间的比较应当用Arrays.equals()
被坑了,数组之间的比较不能用“==”,应当用Arrays.equals() 如果是原生数组(即数组中的值是几大基本数据类型之一的)之间的比较可以直接用,如果数组中的值不是原生的基本数据类型,那么再使用 ...
- Graphics 绘图
Graphics类提供基本绘图方法,Graphics2D类提供更强大的绘图能力. Graphics类提供基本的几何图形绘制方法,主要有:画线段.画矩形.画圆.画带颜色的图形.画椭圆.画圆弧.画多边形等 ...
- 怎么修改Xcode新项目或新文件最上面的Creat By XXX
说明:这个名字是从当前电脑的管理员信息获取的,所以要去修改管理员个人信息. 呵呵 如果改了不行的话,就重启Xcode或者电脑试试吧.
- Python基础教程(022)--Pycharm快速体验
前言 熟悉掌握Python工具 内容 提示 断点调试 目的 学会了解Pycharm的使用 掌握Pycharm执行程序 掌握断点调试模式