Docker网络之容器互联

docker 专栏收录该内容
3 篇文章 0 订阅

一、背景介绍

docker的网络模式有默认有三种:

  1. Host:容器将不会虚拟出自己的网卡,配置自己的IP等,而是使用宿主机的IP和端口。
  2. Bridge:此模式会为每一个容器分配、设置IP等,并将容器连接到一个docker0虚拟网桥,通过docker0网桥以及Iptablesnat表配置与宿主机通信。
  3. None:该模式关闭了容器的网络功能
    本文章只围绕bridge模式进行说明。

二、Docker网络初体验

接下来我们一起通过几个命令揭开Docker网络的神秘面纱

// 查看docker的默认网络
[root@aliyun ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
3d1f04f66edb   bridge    bridge    local
7c23f836a933   host      host      local
b86ba0a2aeae   none      null      local
[root@aliyun ~]# 
//查看当前设备IP 
//docker0(docker虚拟网卡)、eth0(服务器主网卡)、lo(本地回环)
[root@aliyun ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:47:87:24:6d  txqueuelen 0  (Ethernet)
        RX packets 273152  bytes 63352747 (60.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 268028  bytes 42372870 (40.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.130.78  netmask 255.255.240.0  broadcast 172.25.143.255
        ether 00:16:3e:24:38:c3  txqueuelen 1000  (Ethernet)
        RX packets 74785530  bytes 24035620864 (22.3 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 74524351  bytes 36570006245 (34.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1  (Local Loopback)
        RX packets 104  bytes 27553 (26.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 104  bytes 27553 (26.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@aliyun ~]# 
//此时我们创建一个自己的网络 my-net
[root@aliyun ~]# docker network create -d bridge my-net
26239b35f4fd46f822843897fa78e704c0760be5e82b5087f612df9bdf2882d0
[root@aliyun ~]# 
//查看此时的docker网络情况--能看到多了一个我们刚才新建的网络:my-net
[root@aliyun ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
3d1f04f66edb   bridge    bridge    local
7c23f836a933   host      host      local
26239b35f4fd   my-net    bridge    local
b86ba0a2aeae   none      null      local
[root@aliyun ~]# 

docker网络常用命令:来这儿看

三、容器互联

// 用提前下载好的centos镜像容器进行演示
# docker pull centos 
[root@aliyun ~]# docker images
REPOSITORY                                                   TAG       IMAGE ID       CREATED         SIZE
centos                                                       latest    5d0da3dc9764   7 weeks ago     231MB
[root@aliyun ~]# 
// 运行一个centos01容器并连接到我们新建的my-net网络
[root@aliyun ~]# docker run -it -d --network my-net --name centos01 centos
a197c37a0ae1b999079677378e4bf840a0157f8fa62a9c96cc9420b9fbe326cd
[root@aliyun ~]# 
// 运行一个centos00容器并连接到我们新建的my-net网络
[root@aliyun ~]# docker run -it -d --network my-net --name centos02 centos
45c26a860fb518c853e53a997b3d52b61ae13a8d322233db969db6f8ce4c93eb
[root@aliyun ~]# 
//查看当前运行的docker容器
[root@aliyun ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                NAMES
45c26a860fb5   centos         "/bin/bash"              41 seconds ago   Up 40 seconds                                        centos02
a197c37a0ae1   centos         "/bin/bash"              2 minutes ago    Up 2 minutes                                         centos01
[root@aliyun ~]# 
//我们先进入centos01容器中,在centos01容器中连接centos02容器
//这里我们使用容器别名进行互联,执行:ping centos02
[root@aliyun ~]# docker exec -it a197c37a0ae1 /bin/bash
[root@a197c37a0ae1 /]# ping centos02
PING centos02 (172.20.0.3) 56(84) bytes of data.
64 bytes from centos02.my-net (172.20.0.3): icmp_seq=1 ttl=64 time=0.048 ms
64 bytes from centos02.my-net (172.20.0.3): icmp_seq=2 ttl=64 time=0.045 ms
64 bytes from centos02.my-net (172.20.0.3): icmp_seq=3 ttl=64 time=0.056 ms
64 bytes from centos02.my-net (172.20.0.3): icmp_seq=4 ttl=64 time=0.046 ms
^C
--- centos02 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.045/0.048/0.056/0.009 ms
[root@a197c37a0ae1 /]# 
//反向我们先从centos01容器中推出,再进入centos02容器,从centos02容器中连接centos01容器
//这次我们同样使用容器别名进行互联,执行:ping centos01
[root@a197c37a0ae1 /]# exit
exit
[root@aliyun ~]# docker exec -it 45c26a860fb5 /bin/bash
[root@45c26a860fb5 /]# ping centos01
PING centos01 (172.20.0.2) 56(84) bytes of data.
64 bytes from centos01.my-net (172.20.0.2): icmp_seq=1 ttl=64 time=0.042 ms
64 bytes from centos01.my-net (172.20.0.2): icmp_seq=2 ttl=64 time=0.058 ms
64 bytes from centos01.my-net (172.20.0.2): icmp_seq=3 ttl=64 time=0.044 ms
64 bytes from centos01.my-net (172.20.0.2): icmp_seq=4 ttl=64 time=0.051 ms
^C
--- centos01 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.042/0.048/0.058/0.010 ms
[root@45c26a860fb5 /]# 

四、回顾

现在我们再看一下服务器IP,此时会发现多了一个虚拟网卡:br-26239b35f4fd,网关:172.20.0.1

[root@aliyun ~]# ifconfig
br-26239b35f4fd: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.0.1  netmask 255.255.0.0  broadcast 172.20.255.255
        ether 02:42:b8:e0:5c:11  txqueuelen 0  (Ethernet)
        RX packets 74811206  bytes 24037568771 (22.3 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 74582674  bytes 36575345239 (34.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:47:87:24:6d  txqueuelen 0  (Ethernet)
        RX packets 278495  bytes 63728972 (60.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 273407  bytes 42765116 (40.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.130.78  netmask 255.255.240.0  broadcast 172.25.143.255
        ether 00:16:3e:24:38:c3  txqueuelen 1000  (Ethernet)
        RX packets 74811206  bytes 24037568771 (22.3 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 74582674  bytes 36575345239 (34.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1  (Local Loopback)
        RX packets 104  bytes 27553 (26.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 104  bytes 27553 (26.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

我们再看一下centos01容器和centos02容器的IP

[root@aliyun ~]# docker inspect centos01
[
    {
        "Id": "a197c37a0ae1b999079677378e4bf840a0157f8fa62a9c96cc9420b9fbe326cd",
        "Created": "2021-11-04T09:02:29.439612929Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 27443,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-11-04T09:02:29.706789407Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "ResolvConfPath": "/var/lib/docker/containers/a197c37a0ae1b999079677378e4bf840a0157f8fa62a9c96cc9420b9fbe326cd/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/a197c37a0ae1b999079677378e4bf840a0157f8fa62a9c96cc9420b9fbe326cd/hostname",
        "HostsPath": "/var/lib/docker/containers/a197c37a0ae1b999079677378e4bf840a0157f8fa62a9c96cc9420b9fbe326cd/hosts",
        "LogPath": "/var/lib/docker/containers/a197c37a0ae1b999079677378e4bf840a0157f8fa62a9c96cc9420b9fbe326cd/a197c37a0ae1b999079677378e4bf840a0157f8fa62a9c96cc9420b9fbe326cd-json.log",
        "Name": "/centos01",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "my-net",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/dad2a4b1e35af35b9d94366873a7d9501f12708c73f234bf2bddfe4a0406fa27-init/diff:/var/lib/docker/overlay2/a074537de177148607337e332c5227e529f62bf1842de582214640d987d538e3/diff",
                "MergedDir": "/var/lib/docker/overlay2/dad2a4b1e35af35b9d94366873a7d9501f12708c73f234bf2bddfe4a0406fa27/merged",
                "UpperDir": "/var/lib/docker/overlay2/dad2a4b1e35af35b9d94366873a7d9501f12708c73f234bf2bddfe4a0406fa27/diff",
                "WorkDir": "/var/lib/docker/overlay2/dad2a4b1e35af35b9d94366873a7d9501f12708c73f234bf2bddfe4a0406fa27/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "a197c37a0ae1",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20210915",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "377ef8bf846b9f5874dea2e47d682b46289149c817fded8a7f6b80434b73f4f5",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/377ef8bf846b",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "my-net": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "a197c37a0ae1"
                    ],
                    "NetworkID": "26239b35f4fd46f822843897fa78e704c0760be5e82b5087f612df9bdf2882d0",
                    "EndpointID": "d575f55ca4c5d6552da0acba354cb364fe8dfdb4dd3bc61dbd4cfd572609de25",
                    "Gateway": "172.20.0.1", //网关
                    "IPAddress": "172.20.0.2", //IP
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:14:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@aliyun ~]# 
[root@aliyun ~]# docker inspect centos02
[
    {
        "Id": "45c26a860fb518c853e53a997b3d52b61ae13a8d322233db969db6f8ce4c93eb",
        "Created": "2021-11-04T09:03:48.825040188Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 27640,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-11-04T09:03:49.095651507Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "ResolvConfPath": "/var/lib/docker/containers/45c26a860fb518c853e53a997b3d52b61ae13a8d322233db969db6f8ce4c93eb/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/45c26a860fb518c853e53a997b3d52b61ae13a8d322233db969db6f8ce4c93eb/hostname",
        "HostsPath": "/var/lib/docker/containers/45c26a860fb518c853e53a997b3d52b61ae13a8d322233db969db6f8ce4c93eb/hosts",
        "LogPath": "/var/lib/docker/containers/45c26a860fb518c853e53a997b3d52b61ae13a8d322233db969db6f8ce4c93eb/45c26a860fb518c853e53a997b3d52b61ae13a8d322233db969db6f8ce4c93eb-json.log",
        "Name": "/centos02",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "my-net",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/4fa82db462bfdc43190b3fe94a5d3e272163155c6a606ff3498af9ef749f64fa-init/diff:/var/lib/docker/overlay2/a074537de177148607337e332c5227e529f62bf1842de582214640d987d538e3/diff",
                "MergedDir": "/var/lib/docker/overlay2/4fa82db462bfdc43190b3fe94a5d3e272163155c6a606ff3498af9ef749f64fa/merged",
                "UpperDir": "/var/lib/docker/overlay2/4fa82db462bfdc43190b3fe94a5d3e272163155c6a606ff3498af9ef749f64fa/diff",
                "WorkDir": "/var/lib/docker/overlay2/4fa82db462bfdc43190b3fe94a5d3e272163155c6a606ff3498af9ef749f64fa/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "45c26a860fb5",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20210915",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "a2fce56ef553f4c2892c598a43aa9192fb07247441efa90e7b9aa1d4ea22d40d",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/a2fce56ef553",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "my-net": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "45c26a860fb5"
                    ],
                    "NetworkID": "26239b35f4fd46f822843897fa78e704c0760be5e82b5087f612df9bdf2882d0",
                    "EndpointID": "03776fa9985a6348de387d95ce5888f07bd1b808ec9f1653ee4437051fa72344",
                    "Gateway": "172.20.0.1", //网关
                    "IPAddress": "172.20.0.3", //IP
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:14:00:03",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@aliyun ~]# 

可以看到centos01和centos02在同一个网络:172.20.0.1(my-net网络);我们演示的时候用的是别名测试,有兴趣的可以换成容器的IP再测试一下(肯定没问题)。

我们实际应用的时候比如集群之间的互联,各服务之间的调用都是同理,学会利用docker网络管理并隔离多个容器。

完结。

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 1024 设计师:白松林 返回首页

打赏作者

qq_16320351

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值