当前位置: 首页 > 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;本文将带您深…...

conda相比python好处

Conda 作为 Python 的环境和包管理工具&#xff0c;相比原生 Python 生态&#xff08;如 pip 虚拟环境&#xff09;有许多独特优势&#xff0c;尤其在多项目管理、依赖处理和跨平台兼容性等方面表现更优。以下是 Conda 的核心好处&#xff1a; 一、一站式环境管理&#xff1a…...

前端导出带有合并单元格的列表

// 导出async function exportExcel(fileName "共识调整.xlsx") {// 所有数据const exportData await getAllMainData();// 表头内容let fitstTitleList [];const secondTitleList [];allColumns.value.forEach(column > {if (!column.children) {fitstTitleL…...

2024年赣州旅游投资集团社会招聘笔试真

2024年赣州旅游投资集团社会招聘笔试真 题 ( 满 分 1 0 0 分 时 间 1 2 0 分 钟 ) 一、单选题(每题只有一个正确答案,答错、不答或多答均不得分) 1.纪要的特点不包括()。 A.概括重点 B.指导传达 C. 客观纪实 D.有言必录 【答案】: D 2.1864年,()预言了电磁波的存在,并指出…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

css的定位(position)详解:相对定位 绝对定位 固定定位

在 CSS 中&#xff0c;元素的定位通过 position 属性控制&#xff0c;共有 5 种定位模式&#xff1a;static&#xff08;静态定位&#xff09;、relative&#xff08;相对定位&#xff09;、absolute&#xff08;绝对定位&#xff09;、fixed&#xff08;固定定位&#xff09;和…...

解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错

出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上&#xff0c;所以报错&#xff0c;到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本&#xff0c;cu、torch、cp 的版本一定要对…...

C++中string流知识详解和示例

一、概览与类体系 C 提供三种基于内存字符串的流&#xff0c;定义在 <sstream> 中&#xff1a; std::istringstream&#xff1a;输入流&#xff0c;从已有字符串中读取并解析。std::ostringstream&#xff1a;输出流&#xff0c;向内部缓冲区写入内容&#xff0c;最终取…...

WEB3全栈开发——面试专业技能点P2智能合约开发(Solidity)

一、Solidity合约开发 下面是 Solidity 合约开发 的概念、代码示例及讲解&#xff0c;适合用作学习或写简历项目背景说明。 &#x1f9e0; 一、概念简介&#xff1a;Solidity 合约开发 Solidity 是一种专门为 以太坊&#xff08;Ethereum&#xff09;平台编写智能合约的高级编…...

CSS设置元素的宽度根据其内容自动调整

width: fit-content 是 CSS 中的一个属性值&#xff0c;用于设置元素的宽度根据其内容自动调整&#xff0c;确保宽度刚好容纳内容而不会超出。 效果对比 默认情况&#xff08;width: auto&#xff09;&#xff1a; 块级元素&#xff08;如 <div>&#xff09;会占满父容器…...

AI病理诊断七剑下天山,医疗未来触手可及

一、病理诊断困局&#xff1a;刀尖上的医学艺术 1.1 金标准背后的隐痛 病理诊断被誉为"诊断的诊断"&#xff0c;医生需通过显微镜观察组织切片&#xff0c;在细胞迷宫中捕捉癌变信号。某省病理质控报告显示&#xff0c;基层医院误诊率达12%-15%&#xff0c;专家会诊…...