当前位置: 首页 > news >正文

Docker 网络模型使用详解 (1)Dockers网络基础

目录

环境准备

Dockers 网络基础

1.端口映射

查看随机映射端口范围

 -p可以指定映射到本地端口

映射指定地址和指定端口

映射指定地址 宿主机端口随机分配

 指定传输协议

 端口暴露

容器互联

自定义网络

现在把container7加入到demo_net中

在启动一个容器加入到demo_net

 查看三个容器内部网络

 进行ping测试

使用link参数


网络是激活Docker体系的唯一途径,如果Docker没有比较出色的容器网络,那么Docker根本没有如今的竞争力,起初Docker网络的解决方案并不理想,但是经过最近几年的发展,再加上很多云计算服务商都参与了进来,大批的SDN方案如雨后春笋般的冒了出来。

环境准备

安装docker-ce

[root@localhost ~]#  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

--2023-08-04 13:36:55--  http://mirrors.aliyun.com/repo/Centos-7.repo

正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 42.202.208.238, 42.202.208.239, 42.202.208.240, ...

正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|42.202.208.238|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:2523 (2.5K) [application/octet-stream]

正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[=============================================================>] 2,523       --.-K/s 用时 0.002s  

2023-08-04 13:36:55 (1.38 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

[root@localhost ~]#  yum -y install yum-utils device-mapper-persistent-data lvm2

已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * epel: ftp.riken.jp

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本

软件包 device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 已安装并且是最新版本

软件包 7:lvm2-2.02.187-6.el7_9.5.x86_64 已安装并且是最新版本

无须任何处理

[root@localhost ~]#  yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

已加载插件:fastestmirror, product-id, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo

repo saved to /etc/yum.repos.d/docker-ce.repo

[root@localhost ~]# yum -y install docker-ce

已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * epel: mirror.lzu.edu.cn

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

docker-ce-stable                                                                | 3.5 kB  00:00:00     

软件包 3:docker-ce-24.0.5-1.el7.x86_64 已安装并且是最新版本

无须任何处理

[root@localhost ~]# systemctl restart docker

[root@localhost ~]# systemctl enable docker

阿里云镜像加速

[root@localhost ~]# vim /etc/docker/daemon.json

{

        "registry-mirrors":[ "https://nyakyfun.mirror.aliyuncs.com" ]

}

~                     

[root@localhost ~]# systemctl daemon-reload

[root@localhost ~]# systemctl restart docker

[root@localhost ~]# docker version

Client: Docker Engine - Community

 Version:           24.0.5

 API version:       1.43

 Go version:        go1.20.6

 Git commit:        ced0996

 Built:             Fri Jul 21 20:39:02 2023

 OS/Arch:           linux/amd64

 Context:           default

Server: Docker Engine - Community

 Engine:

  Version:          24.0.5

  API version:      1.43 (minimum version 1.12)

  Go version:       go1.20.6

  Git commit:       a61e2b4

  Built:            Fri Jul 21 20:38:05 2023

  OS/Arch:          linux/amd64

  Experimental:     false

 containerd:

  Version:          1.6.22

  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca

 runc:

  Version:          1.1.8

  GitCommit:        v1.1.8-0-g82f18fe

 docker-init:

  Version:          0.19.0

  GitCommit:        de40ad0

下载镜像

[root@localhost ~]# docker pull nginx

Using default tag: latest

latest: Pulling from library/nginx

Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31

Status: Downloaded newer image for nginx:latest

docker.io/library/nginx:latest

[root@localhost ~]# docker pull busybox

Using default tag: latest

latest: Pulling from library/busybox

5cc84ad355aa: Pull complete

Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678

Status: Downloaded newer image for busybox:latest

docker.io/library/busybox:latest

[root@localhost ~]# docker pull mysql

Using default tag: latest

latest: Pulling from library/mysql

72a69066d2fe: Pull complete

93619dbc5b36: Pull complete

99da31dd6142: Pull complete

626033c43d70: Pull complete

37d5d7efb64e: Pull complete

ac563158d721: Pull complete

d2ba16033dad: Pull complete

688ba7d5c01a: Pull complete

00e060b6d11d: Pull complete

1c04857f594f: Pull complete

4d7cfa90e6ea: Pull complete

e0431212d27d: Pull complete

Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709

Status: Downloaded newer image for mysql:latest

docker.io/library/mysql:latest

[root@localhost ~]# vim /etc/sysctl.conf

net.ipv4.ipforward=1

~                

1.Dockers 网络基础

Docker目前对单节点的设备提供了将容器端口映射到宿主机和容器互联两个网络服务。

1.端口映射

在Docker中容器默认是无法与外部通信的,需要在启动命令中加入对应的参数才允许容器与外界通信。

当Docker中运行一个Web服务时,需要把容器内的Web服务应用程序端口映射到本地宿主机的端口。这样,用户访问宿主机指定的端口的话,就相当于访问容器内部的Web服务端口。

-p选项是随机映射一个端口到容器内部开放端口

[root@localhost ~]#  docker run -d -P --name test1 nginx

f4e45f0f9bcd8af728496d2fd0116b602bff4d4aa66a039ec4df6566bc4058eb

[root@localhost ~]# docker port test1

80/tcp -> 0.0.0.0:32768

80/tcp -> [::]:32768

 查看nginx日志

[root@localhost ~]# docker logs test1

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration

/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/

/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh

10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf

10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf

/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh

/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh

/docker-entrypoint.sh: Configuration complete; ready for start up

2023/08/04 05:46:13 [notice] 1#1: using the "epoll" event method

2023/08/04 05:46:13 [notice] 1#1: nginx/1.21.5

2023/08/04 05:46:13 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)

2023/08/04 05:46:13 [notice] 1#1: OS: Linux 3.10.0-1160.92.1.el7.x86_64

2023/08/04 05:46:13 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576

2023/08/04 05:46:13 [notice] 1#1: start worker processes

2023/08/04 05:46:13 [notice] 1#1: start worker process 31

192.168.50.1 - - [04/Aug/2023:05:47:26 +0000] "GET / HTTP/1.1" 200 615 "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=192.168.50.59%3A32768&oq=192.168.200.111&rsv_pq=ee1be515000ac9da&rsv_t=2aeeT%2FKILYdQRMVlG4UwsNF%2FfwwxU4ZCXdDb%2Bjo2%2FLuk4797OvfrWsFufh8&rqlang=cn&rsv_dl=tb&rsv_enter=0&rsv_btype=t&inputT=5216&rsv_sug3=25&rsv_sug1=16&rsv_sug7=100&bs=192.168.200.111" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0" "-"

2023/08/04 05:47:26 [error] 31#31: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.50.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.50.59:32768", referrer: "http://192.168.50.59:32768/"

192.168.50.1 - - [04/Aug/2023:05:47:26 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "http://192.168.50.59:32768/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0" "-"

查看随机映射端口范围

[root@localhost ~]# cat /proc/sys/net/ipv4/ip_local_port_range

32768 60999

 -p可以指定映射到本地端口

[root@localhost ~]# docker run -d -p 800:80 --name test2 nginx

6ae3a06faf8e84597bcf9fe904cbda35033bedcf62b6bfe45f9aec0a72c927dc

 这种方式会映射到所有接口地址,所有访客都可以通过宿主机所有IP的端口来访问容器。

映射指定地址和指定端口

[root@localhost ~]# docker run -d -p 192.168.50.59:9000:80 --name test3 nginx

5c7f7271226075782a0e4078f9a57a7c996c678eeb1e48a2faa93d56e10ff32e

映射指定地址 宿主机端口随机分配

[root@localhost ~]# docker run -d -p 192.168.50.59::80 --name ttt nginx

bdf2a43e6457e9c79ca17e91f7480539ad98a10a541faf38755229f7bb845a00

[root@localhost ~]# docker port ttt

80/tcp -> 192.168.50.59:32769

 指定传输协议

[root@localhost ~]# docker run -d -p 80:80/tcp --name test5 nginx

4e64bce18d657fa65d7307c0528f5665edd240acde8c1657e0984c999fb5146b

[root@localhost ~]#

2. 端口暴露

端口暴露和端口映射是不一样的首先要暴露端口   才可以映射

Dockerfile的作者一般在包含EXPOSE规则时都只提示哪个端口提供哪个服务。访问时还需要运维人员通过端口映射来指定。--expose和EXPOSE只是为其他命令提供所需信息的元数据。

查看网络配置

[root@localhost ~]# docker inspect test1

 "NetworkSettings": {

            "Bridge": "",

            "SandboxID": "bd6efff9aa793bb9356045380794004f2eb65eb7699187a51becf5ed1bb1ff31",

            "HairpinMode": false,

            "LinkLocalIPv6Address": "",

            "LinkLocalIPv6PrefixLen": 0,

            "Ports": {

                "80/tcp": [

                    {

                        "HostIp": "0.0.0.0",

                        "HostPort": "32768"

                    },

                    {

                        "HostIp": "::",

                        "HostPort": "32768"

                    }

                ]

            },

3.容器互联

容器互联是除了端口映射外另一种可以与容器通信的方式。端口映射的用途是宿主机网络与容器的通信,而容器互联是容器之间的通信。

当前实现容器互联有两种方式,一种是把两个容器放进一个用户自定义的网络中,另一种是使用--link参数(已经弃用,即将删除的功能)。

为什么要使用一个单独的网络来连接两个容器呢?设想一下后端容器需要调用一个数据库环境,数据库容器和后端服务容器如果使用上下文中的暴露端口或者映射端口来通信,势必会把数据库的端口也暴露在外网中,导致数据库容器的安全性大大降低,为了解决这个问题,docker允许用户建立一个独立的网络来放置相应的容器,只有在该网络中的容器才能相互通信,外部容器是无法进入这个特定网络中的。

一个容器可以同时加入多个网络,使用不同地址可以访问不同网络中的容器。

自定义网络

[root@localhost ~]# docker run -itd --name=container7 busybox

d970bd74cad26be2b77a45a8867a018706b73341ded97cf972d59681250c7df5

[root@localhost ~]# docker run -itd --name=container8 busybox

6109755ba4b380e4a88fd890a4e86e9c94de8a6ca55f5090a3116f64642998f0

接下来创建一个独立的容器网络,这里使用bridge驱动(桥接模式),其他可选的值还有overlay和macvlan

[root@localhost ~]# docker network create -d bridge --subnet 172.25.0.0/16 demo_net

fcf5201effd82258391ccbae4b6636f3872da2c03e53daa83aa8cb0550d127a6

[root@localhost ~]# docker network ls

NETWORK ID     NAME                DRIVER    SCOPE

ebcfad6f4255   bridge              bridge    local

b881c67f8813   compose_lnmp_lnmp   bridge    local

fcf5201effd8   demo_net            bridge    local

8104a1b1ed6c   host                host      local

7a7562f2d82d   none                null      local

现在把container7加入到demo_net中

[root@localhost ~]# docker network connect demo_net container7

查看

[root@localhost ~]# docker network inspect demo_net

[

    {

        "Name": "demo_net",

        "Id": "fcf5201effd82258391ccbae4b6636f3872da2c03e53daa83aa8cb0550d127a6",

        "Created": "2023-08-04T14:02:22.853085789+08:00",

        "Scope": "local",

        "Driver": "bridge",

        "EnableIPv6": false,

        "IPAM": {

            "Driver": "default",

            "Options": {},

            "Config": [

                {

                    "Subnet": "172.25.0.0/16"

                }

            ]

        },

        "Internal": false,

        "Attachable": false,

        "Ingress": false,

        "ConfigFrom": {

            "Network": ""

        },

        "ConfigOnly": false,

        "Containers": {

            "d970bd74cad26be2b77a45a8867a018706b73341ded97cf972d59681250c7df5": {

                "Name": "container7",

                "EndpointID": "ad133356137a32a24c45fb4a28b20412cc1f9b376a5eb1f72a0a6db685bdb100",

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

                "IPv4Address": "172.25.0.2/16",

                "IPv6Address": ""

            }

        },

        "Options": {},

        "Labels": {}

    }

]

使用docker network inspect可以查看网络中容器的连接状态。Container7已经在demo_net网络中,注意IP地址使自动分配的。

在启动一个容器加入到demo_net

[root@localhost ~]# docker run --network=demo_net --ip=172.25.3.4 -itd --name=container9 busybox

e60d9237253a9de39991c9e2929a33b8acd60f15aea00aba6c5bb2927d231bfd

查看

[root@localhost ~]# docker network inspect demo_net

[

    {

        "Name": "demo_net",

        "Id": "fcf5201effd82258391ccbae4b6636f3872da2c03e53daa83aa8cb0550d127a6",

        "Created": "2023-08-04T14:02:22.853085789+08:00",

        "Scope": "local",

        "Driver": "bridge",

        "EnableIPv6": false,

        "IPAM": {

            "Driver": "default",

            "Options": {},

            "Config": [

                {

                    "Subnet": "172.25.0.0/16"

                }

            ]

        },

        "Internal": false,

        "Attachable": false,

        "Ingress": false,

        "ConfigFrom": {

            "Network": ""

        },

        "ConfigOnly": false,

        "Containers": {

            "d970bd74cad26be2b77a45a8867a018706b73341ded97cf972d59681250c7df5": {

                "Name": "container7",

                "EndpointID": "ad133356137a32a24c45fb4a28b20412cc1f9b376a5eb1f72a0a6db685bdb100",

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

                "IPv4Address": "172.25.0.2/16",

                "IPv6Address": ""

            },

            "e60d9237253a9de39991c9e2929a33b8acd60f15aea00aba6c5bb2927d231bfd": {

                "Name": "container9",

                "EndpointID": "f774f3ebc8c39817b6497e3c07c747725ee83fb80ce62d1939bc47db44f758eb",

                "MacAddress": "02:42:ac:19:03:04",

                "IPv4Address": "172.25.3.4/16",

                "IPv6Address": ""

            }

        },

        "Options": {},

        "Labels": {}

    }

}

 查看三个容器内部网络

[root@localhost ~]# docker exec -it container7 ifconfig

eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:07  

          inet addr:172.17.0.7  Bcast:172.17.255.255  Mask:255.255.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:8 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:656 (656.0 B)  TX bytes:0 (0.0 B)

eth1      Link encap:Ethernet  HWaddr 02:42:AC:19:00:02  

          inet addr:172.25.0.2  Bcast:172.25.255.255  Mask:255.255.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:13 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:1102 (1.0 KiB)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

[root@localhost ~]# docker exec -it container8 ifconfig

eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:08  

          inet addr:172.17.0.8  Bcast:172.17.255.255  Mask:255.255.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:8 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:656 (656.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

[root@localhost ~]# docker exec -it container9 ifconfig

eth0      Link encap:Ethernet  HWaddr 02:42:AC:19:03:04  

          inet addr:172.25.3.4  Bcast:172.25.255.255  Mask:255.255.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:8 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:656 (656.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

 再看图有没有更清楚

 进行ping测试

[root@localhost ~]#  docker exec -it container7 ping 172.17.0.8

PING 172.17.0.8 (172.17.0.8): 56 data bytes

64 bytes from 172.17.0.8: seq=0 ttl=64 time=0.120 ms

64 bytes from 172.17.0.8: seq=1 ttl=64 time=0.094 ms

64 bytes from 172.17.0.8: seq=2 ttl=64 time=0.093 ms

^C64 bytes from 172.17.0.8: seq=3 ttl=64 time=0.087 ms

^C

--- 172.17.0.8 ping statistics ---

4 packets transmitted, 4 packets received, 0% packet loss

round-trip min/avg/max = 0.087/0.098/0.120 ms

[root@localhost ~]#  docker exec -it container7 ping 172.25.3.4

PING 172.25.3.4 (172.25.3.4): 56 data bytes

64 bytes from 172.25.3.4: seq=0 ttl=64 time=0.107 ms

64 bytes from 172.25.3.4: seq=1 ttl=64 time=0.089 ms

64 bytes from 172.25.3.4: seq=2 ttl=64 time=0.093 ms

^C

--- 172.25.3.4 ping statistics ---

3 packets transmitted, 3 packets received, 0% packet loss

round-trip min/avg/max = 0.089/0.096/0.107 ms

[root@localhost ~]#  docker exec -it container9 ping 172.17.0.8

PING 172.17.0.8 (172.17.0.8): 56 data bytes

--- 172.17.0.8 ping statistics ---

17 packets transmitted, 0 packets received, 100% packet loss

进入容器测试

[root@localhost ~]# docker ps -a

CONTAINER ID   IMAGE                COMMAND                   CREATED          STATUS                        PORTS                                       NAMES

e60d9237253a   busybox              "sh"                      26 minutes ago   Up 26 minutes                                                             container9

6109755ba4b3   busybox              "sh"                      35 minutes ago   Up 35 minutes                                                             container8

d970bd74cad2   busybox              "sh"                      36 minutes ago   Up 36 minutes                                                             container7

 都没有问题

[root@localhost ~]# docker exec -it e6 /bin/sh

/ #  ping 172.17.0.8

PING 172.17.0.8 (172.17.0.8): 56 data bytes

^C

--- 172.17.0.8 ping statistics ---

10 packets transmitted, 0 packets received, 100% packet loss

/ # exit

[root@localhost ~]# docker exec -it d9 /bin/sh

/ # ping 172.17.0.8

PING 172.17.0.8 (172.17.0.8): 56 data bytes

64 bytes from 172.17.0.8: seq=0 ttl=64 time=0.099 ms

64 bytes from 172.17.0.8: seq=1 ttl=64 time=0.094 ms

^C

--- 172.17.0.8 ping statistics ---

2 packets transmitted, 2 packets received, 0% packet loss

round-trip min/avg/max = 0.094/0.096/0.099 ms

/ # ping 172.25.3.4

PING 172.25.3.4 (172.25.3.4): 56 data bytes

64 bytes from 172.25.3.4: seq=0 ttl=64 time=0.075 ms

64 bytes from 172.25.3.4: seq=1 ttl=64 time=0.094 ms

^C

--- 172.25.3.4 ping statistics ---

2 packets transmitted, 2 packets received, 0% packet loss

round-trip min/avg/max = 0.075/0.084/0.094 ms

/ # exit

4.使用link参数

容器的连接(linking)系统是除了端口映射外另一种可以与容器中应用进行交互的方式。它会在源和接收容器之间创建一个隧道,接收容器可以看到源容器指定的信息。

使用这个参数容器必须设置一个名字,也就是--name指定的值。

就是使用建立别名进行通联

[root@localhost ~]# docker run -itd --name  test busybox

9b45c62f24cbbcefcb6d317b21aa0f184580b48015440fb00b0fb29d1e383cab

--link参数的格式: --link name:alias , 其中name是要链接的容器的名称,alias是这个链接的别名。

先建立一个test 在创建一个link 并设置一个test的别名

[root@localhost ~]# docker run -itd --name=link --link test:test busybox

de2bf9cd7428d2e7c35be872451f75202a695a14ca0668b9182b0c98828f838d

[root@localhost ~]# docker exec -it link ping test

PING test (172.17.0.9): 56 data bytes

64 bytes from 172.17.0.9: seq=0 ttl=64 time=0.123 ms

64 bytes from 172.17.0.9: seq=1 ttl=64 time=0.092 ms

64 bytes from 172.17.0.9: seq=2 ttl=64 time=0.093 ms

^C

--- test ping statistics ---

3 packets transmitted, 3 packets received, 0% packet loss

round-trip min/avg/max = 0.092/0.102/0.123 ms

相关文章:

Docker 网络模型使用详解 (1)Dockers网络基础

目录 环境准备 Dockers 网络基础 1.端口映射 查看随机映射端口范围 -p可以指定映射到本地端口 映射指定地址和指定端口 映射指定地址 宿主机端口随机分配 指定传输协议 端口暴露 容器互联 自定义网络 现在把container7加入到demo_net中 在启动一个容器加入到demo_net…...

【Spring】(四)Bean 的作用域和生命周期

文章目录 前言一、Bean 的作用域1.1 被修改的 Bean 案例1.2 作用域的定义1.3 Bean 的六种作用域1.4 Bean 作用域的设置 二、Spring 的执行流程 和 Bean 的生命周期2.1 Spring 的执行流程2.2 Bean 的生命周期2.3 Bean 生命周期的演示 前言 Bean 是 Spring 框架中的一个核心概念…...

卷积神经网络【图解CNN】

文章目录 1.卷积运算2.池化3.全连接层 卷积神经网络可以看作一个函数或者黑箱,输入就是图片的像素阵列,输出就是这个图片是什么? 图片是X,那么就输出‘x’,图片是‘O’,那么就输出O; 在计算机眼中&#xff…...

命令模式 Command Pattern 《游戏设计模式》学习笔记

对于一般的按键输入,我们通常这么做,直接if按了什么键,就执行相应的操作 在这里我们是将用户的输入和程序行为硬编码在一起,这是我们很自然就想到的最快的做法。 但是如果这是一个大型游戏,往往我们需要实现一个按键…...

供水管网漏损监测,24小时保障城市供水安全

供水管网作为城市生命线重要组成部分,其安全运行是城市建设和人民生活的基本保障。随着我国社会经济的快速发展和城市化进程的加快,城市供水管网的建设规模日益增长。然而,由于管网老化、外力破坏和不当维护等因素导致的供水管网漏损&#xf…...

How to Use Glslang

文章目录 Execution of Standalone Wrapper构建 (CMake)依赖关系构建步骤如果需要更改 GLSL 语法测试运行测试基本内部操作 Execution of Standalone Wrapper 要使用独立的二进制形式,请执行glslang,它将打印一条使用语句。基本操作是给它一个包含着色器…...

AcWing 24:机器人的运动范围 ← BFS、DFS

【题目来源】https://www.acwing.com/problem/content/description/22/【题目描述】 地上有一个 m 行和 n 列的方格,横纵坐标范围分别是 0∼m−1 和 0∼n−1。 一个机器人从坐标 (0,0) 的格子开始移动,每一次只能向左,右,上&#…...

RF手机天线仿真介绍(一):金属边框天线和LDS天线

目录 简介LDS天线LDS天线仿真 金属边框天线金属边框天线仿真 简介 最早的手机是外置式天线,从NOKIA开始采用内置式天线,开始采用内置金属片(一般是0.1MM厚的不锈钢片冲压而成),随后为降低成本,后来改用FPC…...

动手学深度学习—深度学习计算(层和块、参数管理、自定义层和读写文件)

目录 1. 层和块1.1 自定义块1.2 顺序块1.3 在前向传播函数中执行代码 2. 参数管理2.1 参数访问2.1.1 目标参数2.1.2 一次性访问所有参数2.1.3 从嵌套块收集参数 2.2 参数初始化2.2.1 内置初始化2.2.2 自定义初始化 2.3 参数绑定 3. 自定义层3.1 不带参数的层3.2 带参数的层 4. …...

Pytest学习教程_测试报告生成pytest-html(三)

前言 pytest-html 是一个用于生成漂亮的 HTML 测试报告的 pytest 插件。它可以方便地将 pytest 运行的测试结果转换为易于阅读和理解的 HTML 报告,提供了丰富的测试结果展示功能和交互性。 一、安装 # 版本查看命令 pytest版本: pytest --version pyte…...

模块化原理:source-map

1. webpack打包基本配置 1.安装webpack与webpack-cli npm i webpack webpack-cli 2.配置 "build":"webpack" 3. 新建webpack.config.js const path require(path); module.exports {// mode: "development",// 默认production(什么…...

【C++】开源:ncurses终端TUI文本界面库

😏★,:.☆( ̄▽ ̄)/$:.★ 😏 这篇文章主要介绍ncurses终端文本界面库。 无专精则不能成,无涉猎则不能通。——梁启超 欢迎来到我的博客,一起学习,共同进步。 喜欢的朋友可以关注一下,下…...

C语言的_Bool类型

C99 新增了 _Bool 类型&#xff0c;用于表示布尔值&#xff0c;即逻辑值 true 和 false。 _Bool 类型也是一种整数类型。 原则上 _Bool 类型只占用一位存储空间。 C语言将非 0 的数当为 true&#xff0c;0 当为 false。 代码示例&#xff1a; #include<stdio.h> int…...

【python爬虫】获取某一个网址下面抓取所有的a 超链接下面的内容

import requests as rq from bs4 import BeautifulSoup as bs import re# rooturl是传的是我需要查询和抓取的一个网址&#xff0c;可以是html js 等 def gethtml(rooturl, encoding"utf-8"):#默认解码方式utf-8response rq.get(rooturl)response.encoding encodin…...

AutoDL从0到1搭建stable-diffusion-webui

前言 AI绘画当前非常的火爆&#xff0c;随着Stable diffusion&#xff0c;Midjourney的出现将AI绘画推到顶端&#xff0c;各大行业均受其影响&#xff0c;离我们最近的AI绘画当属Stable diffusion&#xff0c;可本地化部署&#xff0c;只需电脑配备显卡即可完成AI绘画工作&…...

手动调整broker扩容后的旧topic分区

在broker扩容了两台机器之后&#xff0c;想让旧topic&#xff1a;quickstart76-events的分区也能铺满broker 1、创建一个topics-to-move.json json文件 $ vim topics-to-move.json json {"topics": [{"topic":"quickstart76-events"}],"v…...

【LeetCode-简单】剑指 Offer 25. 合并两个排序的链表(详解)

题目 入两个递增排序的链表&#xff0c;合并这两个链表并使新链表中的节点仍然是递增排序的。 示例1&#xff1a; 输入&#xff1a;1->2->4, 1->3->4 输出&#xff1a;1->1->2->3->4->4 本题与主站 21 题相同&#xff1a;力扣 题目地址&#x…...

Java版工程行业管理系统源码-专业的工程管理软件-em提供一站式服务

​ Java版工程项目管理系统 Spring CloudSpring BootMybatisVueElementUI前后端分离 功能清单如下&#xff1a; 首页 工作台&#xff1a;待办工作、消息通知、预警信息&#xff0c;点击可进入相应的列表 项目进度图表&#xff1a;选择&#xff08;总体或单个&#xff09;项目…...

【Spring】简化事件的使用,Spring提供了2种使用方式

Spring中事件可以配置顺序&#xff0c;利用线程池还可以做异步线程通知。怎么样使用事件&#xff1f;Spring简化事件的使用&#xff0c;Spring提供了2种使用方式&#xff1a;面向接口和面向EventListener注解。 1,面相接口的方式 案例 发布事件 需要先继承ApplicationEventP…...

探究Spring事务:了解失效场景及应对策略

在现代软件开发中&#xff0c;数据的一致性和完整性是至关重要的。为了保证这些特性&#xff0c;Spring框架提供了强大的事务管理机制&#xff0c;让开发者能够更加自信地处理数据库操作。然而&#xff0c;事务并非银弹&#xff0c;存在一些失效的情景&#xff0c;本文将带您深…...

Spark 之 入门讲解详细版(1)

1、简介 1.1 Spark简介 Spark是加州大学伯克利分校AMP实验室&#xff08;Algorithms, Machines, and People Lab&#xff09;开发通用内存并行计算框架。Spark在2013年6月进入Apache成为孵化项目&#xff0c;8个月后成为Apache顶级项目&#xff0c;速度之快足见过人之处&…...

练习(含atoi的模拟实现,自定义类型等练习)

一、结构体大小的计算及位段 &#xff08;结构体大小计算及位段 详解请看&#xff1a;自定义类型&#xff1a;结构体进阶-CSDN博客&#xff09; 1.在32位系统环境&#xff0c;编译选项为4字节对齐&#xff0c;那么sizeof(A)和sizeof(B)是多少&#xff1f; #pragma pack(4)st…...

【网络安全产品大调研系列】2. 体验漏洞扫描

前言 2023 年漏洞扫描服务市场规模预计为 3.06&#xff08;十亿美元&#xff09;。漏洞扫描服务市场行业预计将从 2024 年的 3.48&#xff08;十亿美元&#xff09;增长到 2032 年的 9.54&#xff08;十亿美元&#xff09;。预测期内漏洞扫描服务市场 CAGR&#xff08;增长率&…...

对WWDC 2025 Keynote 内容的预测

借助我们以往对苹果公司发展路径的深入研究经验&#xff0c;以及大语言模型的分析能力&#xff0c;我们系统梳理了多年来苹果 WWDC 主题演讲的规律。在 WWDC 2025 即将揭幕之际&#xff0c;我们让 ChatGPT 对今年的 Keynote 内容进行了一个初步预测&#xff0c;聊作存档。等到明…...

使用van-uploader 的UI组件,结合vue2如何实现图片上传组件的封装

以下是基于 vant-ui&#xff08;适配 Vue2 版本 &#xff09;实现截图中照片上传预览、删除功能&#xff0c;并封装成可复用组件的完整代码&#xff0c;包含样式和逻辑实现&#xff0c;可直接在 Vue2 项目中使用&#xff1a; 1. 封装的图片上传组件 ImageUploader.vue <te…...

ArcGIS Pro制作水平横向图例+多级标注

今天介绍下载ArcGIS Pro中如何设置水平横向图例。 之前我们介绍了ArcGIS的横向图例制作&#xff1a;ArcGIS横向、多列图例、顺序重排、符号居中、批量更改图例符号等等&#xff08;ArcGIS出图图例8大技巧&#xff09;&#xff0c;那这次我们看看ArcGIS Pro如何更加快捷的操作。…...

Linux --进程控制

本文从以下五个方面来初步认识进程控制&#xff1a; 目录 进程创建 进程终止 进程等待 进程替换 模拟实现一个微型shell 进程创建 在Linux系统中我们可以在一个进程使用系统调用fork()来创建子进程&#xff0c;创建出来的进程就是子进程&#xff0c;原来的进程为父进程。…...

FFmpeg:Windows系统小白安装及其使用

一、安装 1.访问官网 Download FFmpeg 2.点击版本目录 3.选择版本点击安装 注意这里选择的是【release buids】&#xff0c;注意左上角标题 例如我安装在目录 F:\FFmpeg 4.解压 5.添加环境变量 把你解压后的bin目录&#xff08;即exe所在文件夹&#xff09;加入系统变量…...

华为OD最新机试真题-数组组成的最小数字-OD统一考试(B卷)

题目描述 给定一个整型数组,请从该数组中选择3个元素 组成最小数字并输出 (如果数组长度小于3,则选择数组中所有元素来组成最小数字)。 输入描述 行用半角逗号分割的字符串记录的整型数组,0<数组长度<= 100,0<整数的取值范围<= 10000。 输出描述 由3个元素组成…...

C++实现分布式网络通信框架RPC(2)——rpc发布端

有了上篇文章的项目的基本知识的了解&#xff0c;现在我们就开始构建项目。 目录 一、构建工程目录 二、本地服务发布成RPC服务 2.1理解RPC发布 2.2实现 三、Mprpc框架的基础类设计 3.1框架的初始化类 MprpcApplication 代码实现 3.2读取配置文件类 MprpcConfig 代码实现…...