docker 基于link 的互联
默认情况下,容器使互联的。docker 默认使允许container 互通的,通过-icc=false 关闭互通。一旦关闭了互通,只能通过-link name:alias 命令连接指定container .–link redis:db 的别名,会在/etc/hosts 中生成对应的IP映射创建一个打开了3306 端口的mysql 临时容器root@ubuntu:~# dock...
·
默认情况下,容器使互联的。
docker 默认使允许container 互通的,通过-icc=false 关闭互通。一旦关闭了互通,只能通过-link name:alias 命令连接指定container .
–link redis:db 的别名,会在/etc/hosts 中生成对应的IP映射
创建一个打开了3306 端口的mysql 临时容器
root@ubuntu:~# docker run --rm=true --name=mysqlserver -e MYSQL_ROOT_PASSWORD=1234 56 mysql
在docker 机制下,请求此docker 容器端口
root@ubuntu:~# docker run --rm=true java curl 172.17.03:3306
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 104 0 104 0 0 2616 0 --:--:-- --:--:-- --:--:-- 4000
8.0.16[i7m&▒▒▒▒▒0u(?+Lo%d/caching_sha2_password▒Got packets out of orderroot@ubunt
给一个主机名(DNS名称) 用来代替IP 地址进行访问
目标容器(需要连接的容器)
root@ubuntu:~# docker run --rm=true --name=myjavaserver -it java /bin/bash
root@ubuntu:~# docker run --rm=true --link=myjaveserver:serverM1 -it java /bin/bash
docker: Error response from daemon: Could not get container for myjaveserver.
See 'docker run --help'.
root@ubuntu:~# docker run --rm=true --link=myjavaserver:serverM1 -it java /bin/bash
root@bab4b6b56a99:/# ping myjavaserver
PING serverM1 (172.17.0.4): 56 data bytes
64 bytes from 172.17.0.4: icmp_seq=0 ttl=64 time=0.224 ms
64 bytes from 172.17.0.4: icmp_seq=1 ttl=64 time=0.080 ms
^C--- serverM1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.080/0.152/0.224/0.072 ms
root@bab4b6b56a99:/# ping serverM1
PING serverM1 (172.17.0.4): 56 data bytes
64 bytes from 172.17.0.4: icmp_seq=0 ttl=64 time=0.073 ms
64 bytes from 172.17.0.4: icmp_seq=1 ttl=64 time=0.077 ms
^C--- serverM1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.073/0.075/0.077/0.000 ms
root@ubuntu:~# docker run --rm=true -it java ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: icmp_seq=0 ttl=64 time=0.260 ms
64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.072 ms
64 bytes from 172.17.0.1: icmp_seq=2 ttl=64 time=0.071 ms
64 bytes from 172.17.0.1: icmp_seq=3 ttl=64 time=0.071 ms
64 bytes from 172.17.0.1: icmp_seq=4 ttl=64 time=0.090 ms
64 bytes from 172.17.0.1: icmp_seq=5 ttl=64 time=0.072 ms
现在关闭这个互联功能
无法ping 通 ,但是可以访问其端口
更多推荐
已为社区贡献5条内容
所有评论(0)