Docker互联网,从零教你怎样完成器皿互联网有关专业知识

Docker互联网

了解Docker0

清除全部自然环境

检测

image

三个互联网

#难题:docker 是如何处理器皿互联网浏览

image

[root@hsStudy /]# docker run -d -P --name tomcat01 tomcat

#查询器皿的內部IP地址 ip addr , 发觉器皿运行的情况下会获得个  eth0@if83 ip详细地址,docker分派的!
[root@hsStudy /]# docker exec -it tomcat01 ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    iNET 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
6: eth0@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever


# 思索,Linux 能否 ping 通器皿內部
[root@hsStudy /]# ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.604 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.121 ms
64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.101 ms
64 bytes from 172.17.0.2: icmp_seq=4 ttl=64 time=0.121 ms
64 bytes from 172.17.0.2: icmp_seq=5 ttl=64 time=0.223 ms

# linux 能够 ping 通 docker 器皿內部

基本原理

大家每运行一个docker器皿,docker便会给docker器皿分派izgeip,大家只需安裝了docker,便会有一个网口docker0桥接模式,应用的技术性是evth-pair技术性

再度检测 ip addr

image

2.重新启动一个器皿检测,发觉又多了一个网口

image

image

# 大家发觉这一器皿产生的网口,全是一对一对的
# evth-pair 便是一对的虚似机器设备端口号,她们全是成对发生的,一段连到协议书,一段彼此之间相接
# 正由于有这一技术性,evth-pair当做一个公路桥梁,联接各种各样互联网络机器设备
# OpenStac, Docker器皿中间的联接,OVS的联接,全是应用 evth-pair 技术性

3.大家检测下tocmat01 和 tomcat02 是不是能够 ping通

[root@hsStudy ~]# docker exec -it tomcat01 ping 127.0.01

#结果:器皿和器皿中间是能够 相互之间ping通的!

制作一个网络模型图:

image
结果:tomcat01 和tomcat02 是公共的一个无线路由器,docker0.

全部的器皿不特定互联网的状况下,全是docker0路由器的,docker会给大家的器皿分派一个默认设置的可用ip

总结

Docker 应用的是linux的中继,宿主机中是一个Docker器皿的网桥 docker0

image
Docker 中的全部的网线端口全是虚似的。虚似的分享高效率!(内部网传送文档!)

关键器皿删掉,相匹配网桥一对就没有了!

image

思索一个情景,大家撰写了一个微服务架构,database url=ip: , 新项目不重新启动,数据库查询ip更换了,大家期待能够 解决这个问题,可以用名称来开展访器皿?

[root@hsStudy ~]# docker exec -it tomcat02 ping tomcat01
ping: tomcat01: Name or Service not known

# 如何解决呢?
[root@hsStudy ~]# docker exec -it tomcat02 ping tomcat01
ping: tomcat01: Name or service not known

# 根据--link,就可以处理互联网连接难题了
[root@hsStudy ~]# docker run -d -P --name tomcat03 --link tomcat02 tomcat
c415309affcf62445fef38a33ec145eb4ee90926e6ef8acb46ea195eb9c2225a
[root@hsStudy ~]# docker exec -it tomcat03 ping tomcat02
PING tomcat02 (172.17.0.3) 56(84) bytes of data.
64 bytes from tomcat02 (172.17.0.3): icmp_seq=1 ttl=64 time=0.511 ms
64 bytes from tomcat02 (172.17.0.3): icmp_seq=2 ttl=64 time=0.334 ms
64 bytes from tomcat02 (172.17.0.3): icmp_seq=3 ttl=64 time=0.110 ms

rtt min/avg/max/mdev = 0.079/0.197/0.511/0.143 ms



#反方向能够 ping通吗
[root@hsStudy ~]# docker exec -it tomcat02 ping tomcat03
ping: tomcat03: Name or service not known

研究:inspect

[root@hsStudy ~]# docker Network inspect bfa725a8822a

image
实际上这一tomcat03,便是在当地配备了tomcat02的配备?

# 查询 hosts 配备,在这儿基本原理发觉!
[root@hsStudy ~]# docker exec -it tomcat03 cat /etc/hosts
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allNodes
ff02::2	ip6-allrouters
172.17.0.3	tomcat02 1cfbb3ded9dc
172.17.0.4	c415309affcf

实质研究:--link 便是我们在hosts配备中提升了一个172.17.0.3 tomcat02 1cfbb3ded9dc

大家如今玩docker早已不建议应用--link了 !

自定互联网!不适合docker0!

docker0难题:它不兼容器皿名联接浏览!

自定互联网

查询全部的docker互联网

image
网络模式

bridge : 中继 docker (默认设置,自身建立也应用bridge 方式

none : 不配备互联网

host:和宿主机分享网络

container : 器皿内互联网连接!(用的少!局限性非常大)

检测

# 大家立即运行的指令 --net bridge,而这一便是大家的docker0
docker run -d -P --name tomcat01 tomcat 
docker run -d -P --name tomcat01 --net bridge tomcat 

# docker0的特性: 默认设置,网站域名不可以浏览, --link能够 连通联接

# 我们可以自定一个互联网!
# --driver bridge
# --subnet 192.168.0.0/16  192.168.0.2  192.168.225.255
# --gateway 192.168.0.1


[root@hsStudy /]# docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet 
565113e68fc8dc5b199b07c1f3865d4c9bfac30c8cbfaffcf4c3b94143a64c30

[root@hsStudy /]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
bfa725a8822a   bridge    bridge    local
7a1183d31c91   host      host      local
565113e68fc8   mynet     bridge    local
9389bf2c80c7   none      null      local

我们自己的互联网就建立

image

[root@hsStudy ~]# docker network inspect mynet
[
    {
        "Name": "mynet",
        "Id": "565113e68fc8dc5b199b07c1f3865d4c9bfac30c8cbfaffcf4c3b94143a64c30",
        "Created": "2021-05-21T17:59:18.871143496 08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPV6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.0.0/16",
                    "Gateway": "192.168.0.1"
                }
            ]
        },
        "internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "296821282f9b21c5b3459ea565636366506b68fbd0632f24dbaeeb85d5d3e830": {
                "Name": "tomcat-net-02",
                "EndpointID": "d5773944cecfa28ba633592ffaa7a8f9404a1d14209e387eafc2ef86d114baad",
                "MacAddress": "02:42:c0:a8:00:03",
                "IPV4Address": "192.168.0.3/16",
                "IPv6Address": ""
            },
            "521bb80f0334c216968a2528dcc54818f3cc026e4c2d37e31db2376da1492f1f": {
                "Name": "tomcat-net-01",
                "EndpointID": "b833f7131f10a775a743143a3e8aee7aeace8d12a315c100b8ff353a6975991f",
                "MacAddress": "02:42:c0:a8:00:02",
                "IPv4Address": "192.168.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

#再度检测ping联接,如今不应用--link 还可以ping名称了
[root@hsStudy ~]# docker exec -it tomcat-net-01 ping 192.168.0.3
PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data.
64 bytes from 192.168.0.3: icmp_seq=1 ttl=64 time=0.259 ms
64 bytes from 192.168.0.3: icmp_seq=2 ttl=64 time=0.102 ms
64 bytes from 192.168.0.3: icmp_seq=3 ttl=64 time=0.088 ms
64 bytes from 192.168.0.3: icmp_seq=4 ttl=64 time=0.091 ms
64 bytes from 192.168.0.3: icmp_seq=5 ttl=64 time=0.253 ms
64 bytes from 192.168.0.3: icmp_seq=6 ttl=64 time=0.084 ms
^C
--- 192.168.0.3 ping statistics ---
6 packets transmitted, 6 received, 0% packet Loss, time 31ms
rtt min/avg/max/mdev = 0.084/0.146/0.259/0.078 ms
[root@hsStudy ~]# docker exec -it tomcat-net-01 ping tomcat-net-02
PING tomcat-net-02 (192.168.0.3) 56(84) bytes of data.
64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=1 ttl=64 time=0.448 ms
64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=2 ttl=64 time=0.177 ms
64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=3 ttl=64 time=0.214 ms
64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=4 ttl=64 time=0.132 ms
^C
--- tomcat-net-02 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 6ms
rtt min/avg/max/mdev = 0.132/0.242/0.448/0.123 ms

大家自定的互联网docker都早已帮大家维护保养好啦相匹配的关联,强烈推荐大家平常那样应用互联网!

益处:

redis-群集

MySQL-群集

不一样的群集应用不一样的互联网,确保群集是安全性和身心健康

互联网连接

让tomcat-01联接到tomcat-net-01必须如何做?

image

image

image

# 检测连通 tomcat01 - mynet

# 连接以后,便是将大家的tomcat01 添加到mynet互联网下

# 一个器皿2个ip详细地址,阿里服务器器一个外网地址ip,一个私网ip

image
如今就可以tomcat01 ping 通 tomcat-net-01 了

[root@hsStudy ~]# docker exec -it tomcat01 ping tomcat-net-01
PING tomcat-net-01 (192.168.0.2) 56(84) bytes of data.
64 bytes from tomcat-net-01.mynet (192.168.0.2): icmp_seq=1 ttl=64 time=0.230 ms
64 bytes from tomcat-net-01.mynet (192.168.0.2): icmp_seq=2 ttl=64 time=0.414 ms
64 bytes from tomcat-net-01.mynet (192.168.0.2): icmp_seq=3 ttl=64 time=0.757 ms
64 bytes from tomcat-net-01.mynet (192.168.0.2): icmp_seq=4 ttl=64 time=0.103 ms
64 bytes from tomcat-net-01.mynet (192.168.0.2): icmp_seq=5 ttl=64 time=0.148 ms
^C
--- tomcat-net-01 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 十米s
rtt min/avg/max/mdev = 0.103/0.330/0.757/0.238 ms

# 02 是依然打堵塞的
[root@hsStudy ~]# docker exec -it tomcat02 ping tomcat-net-01
ping: tomcat-net-01: Temporary failure in name resolution


结果:假定必须跨数据连接人就必须应用docker network 连接!

实战演练:布署Redis群集

image
shell脚本制作

 # 建立网口
 [root@hsStudy ~]# docker network create redis --subnet 172.38.0.0/16 

# 根据脚本制作建立六个redis配备


for port in $(seq 1 6); \
do \
mkdir -p /mydata/redis/node-${port}/conf
touch /mydata/redis/node-${port}/conf/redis.conf
cat  EOF /mydata/redis/node-${port}/conf/redis.conf
port 6379 
bind 0.0.0.0
cluster-enabled yes 
cluster-config-File nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.38.0.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done


docker run -p 6371:6379 -p 16371:16379 --name redis-1 \
    -v /mydata/redis/node-1/data:/data \
    -v /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf \
    -d --net redis --ip 172.38.0.11 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf


image

SpringBoot微服务架构装包Docker镜像系统

  1. 构架SpringBoot 新项目
  2. 装包运用
  3. 撰写dockerfile
  4. 搭建镜像系统
  5. 公布运作

之后大家应用了Docker以后,给他人交货的是一个镜像系统就可以!

学得了这儿大家早已彻底足够了Docker!

评论(0条)

刀客源码 请登录后评论