Docker 实战 - 局域网络搭建

news/2024/11/29 9:33:30/

Docker 实战 - 局域网络搭建

1、docker network 命令

PS C:\Users\xiaozy> docker network --helpUsage:  docker network COMMANDManage networksCommands:connect     Connect a container to a networkcreate      Create a networkdisconnect  Disconnect a container from a networkinspect     Display detailed information on one or more networks # 显示局域网详细信息ls          List networks                                        # 罗列所有局域网prune       Remove all unused networksrm          Remove one or more networks

2、创建局域网

创建局域网:

PS C:\Users\xiaozy37528> docker network create myNetwork
f26e19d32597aec0a762c2e7081f86de930aa885b90c983a78730af2a6a018e6

罗列所有局域网:

PS C:\Users\xiaozy37528> docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
cb5ee1a12afa   bridge            bridge    local
9b5cbe43e4fb   example_default   bridge    local
26e5ebb8f04c   host              host      local
f26e19d32597   myNetwork         bridge    local
ccc51ee1d166   none              null      local

查看局域网详细信息:

PS C:\Users\xiaozy37528> docker network inspect myNetwork
[{"Name": "myNetwork","Id": "f26e19d32597aec0a762c2e7081f86de930aa885b90c983a78730af2a6a018e6","Created": "2022-01-26T03:11:03.8063259Z","Scope": "local","Driver": "bridge","EnableIPv6": false,"IPAM": {"Driver": "default","Options": {},"Config": [{"Subnet": "172.19.0.0/16","Gateway": "172.19.0.1"}]},"Internal": false,"Attachable": false,"Ingress": false,"ConfigFrom": {"Network": ""},"ConfigOnly": false,"Containers": {},"Options": {},"Labels": {}}
]

3、容器连接到局域网

将容器连接到局域网有两种方式:

  1. 启动容器时加入

    docker run -itd --name myRedis --network myNetwork --network-alias redis -p 6379:6379 redis
    
  2. 启动容器后加入

    docker network connect myNetwork redis
    
    PS C:\Users\xiaozy37528> docker container ls
    CONTAINER ID   IMAGE                COMMAND                  CREATED      STATUS          PORTS                                       NAMES
    85f3be5e8ee0   nginx                "/docker-entrypoint.…"   2 days ago   Up 33 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp           MyNginx
    c824254e2a94   nacos/nacos-server   "bin/docker-startup.…"   6 days ago   Up 2 hours      0.0.0.0:8848->8848/tcp, :::8848->8848/tcp   nacos
    PS C:\Users\xiaozy37528> docker network connect myNetwork MyNginx
    PS C:\Users\xiaozy37528> docker network connect myNetwork nacos
    PS C:\Users\xiaozy37528> docker network inspect myNetwork
    [{"Name": "myNetwork","Id": "f26e19d32597aec0a762c2e7081f86de930aa885b90c983a78730af2a6a018e6","Created": "2022-01-26T03:11:03.8063259Z","Scope": "local","Driver": "bridge","EnableIPv6": false,"IPAM": {"Driver": "default","Options": {},"Config": [{"Subnet": "172.19.0.0/16","Gateway": "172.19.0.1"}]},"Internal": false,"Attachable": false,"Ingress": false,"ConfigFrom": {"Network": ""},"ConfigOnly": false,"Containers": {"85f3be5e8ee00b51ce5cf1cf88e105cdffe2ea312bf8a9a30d0f3343a582c231": {"Name": "MyNginx","EndpointID": "d9a7a59c21221a96b626435ac77facd382de425a51513ef61ca7d8b8aa7c6843","MacAddress": "02:42:ac:13:00:02","IPv4Address": "172.19.0.2/16","IPv6Address": ""},"c824254e2a94bd32a5c216a0978e4ef7959cce6331a9ac220d75debd4593666c": {"Name": "nacos","EndpointID": "a2119d6c6742bd886ec19e910c207c20011e532d25f9f8afb0b2f59533fda13d","MacAddress": "02:42:ac:13:00:03","IPv4Address": "172.19.0.3/16","IPv6Address": ""}},"Options": {},"Labels": {}}
    ]
    

4、验证

Nacos 容器 ping Nginx 容器:

PS C:\Users\xiaozy37528> docker exec -it nacos /bin/bash
[root@c824254e2a94 nacos]# ping 172.19.0.2
PING 172.19.0.2 (172.19.0.2) 56(84) bytes of data.
64 bytes from 172.19.0.2: icmp_seq=1 ttl=64 time=0.142 ms
64 bytes from 172.19.0.2: icmp_seq=2 ttl=64 time=0.038 ms
clea64 bytes from 172.19.0.2: icmp_seq=3 ttl=64 time=0.050 ms
64 bytes from 172.19.0.2: icmp_seq=4 ttl=64 time=0.037 ms
64 bytes from 172.19.0.2: icmp_seq=5 ttl=64 time=0.053 ms
64 bytes from 172.19.0.2: icmp_seq=6 ttl=64 time=0.037 ms
64 bytes from 172.19.0.2: icmp_seq=7 ttl=64 time=0.039 ms
64 bytes from 172.19.0.2: icmp_seq=8 ttl=64 time=0.033 ms
64 bytes from 172.19.0.2: icmp_seq=9 ttl=64 time=0.040 ms
64 bytes from 172.19.0.2: icmp_seq=10 ttl=64 time=0.039 ms
64 bytes from 172.19.0.2: icmp_seq=11 ttl=64 time=0.050 ms
64 bytes from 172.19.0.2: icmp_seq=12 ttl=64 time=0.041 ms
64 bytes from 172.19.0.2: icmp_seq=13 ttl=64 time=0.052 ms
64 bytes from 172.19.0.2: icmp_seq=14 ttl=64 time=0.091 ms
64 bytes from 172.19.0.2: icmp_seq=15 ttl=64 time=0.049 ms
64 bytes from 172.19.0.2: icmp_seq=16 ttl=64 time=0.041 ms
64 bytes from 172.19.0.2: icmp_seq=17 ttl=64 time=0.055 ms
64 bytes from 172.19.0.2: icmp_seq=18 ttl=64 time=0.037 ms
--- 172.19.0.2 ping statistics ---
18 packets transmitted, 18 received, 0% packet loss, time 17692ms
rtt min/avg/max/mdev = 0.033/0.051/0.142/0.026 ms
[root@c824254e2a94 nacos]#

Nginx 容器 ping Nacos 容器:


http://www.ppmy.cn/news/798247.html

相关文章

12.1 局域运算

1.加载数据 2.打开空间分析工具

复杂网络多局域世界模型matlab算法实现

3.12多局域世界模型 3.12.1 多局域世界模型的构造方法(1) 以概率p增加一个拥有m0个节点,e0条边的局域世界,代码如下:(2)选定一个已存在的局域世界,以概率q将一个新节点,以给定概率同局域世界中的点建立m1条边(3) 以概率r向局域世界增加m条边(4) 在一个网络中删除m…

局域网点歌软件

软件简介 易语言开发 局域网简易点歌系统是一款类似网吧点歌软件,可以帮助用户将搜索到的网易云音乐、QQ音乐、酷狗、酷我、虾米和百度音乐里的音乐资源都通过局域网进行点歌。主要功能包括:点播歌曲,聊天功能,歌曲搜索&#x…

DRF+Vue.JS前后端分离项目实例(下) --- Vue.js 前端实现代码

本文上篇请 点击阅读 1. 需求说明 本文以学生信息查询功能为例,采用前后端分离架构,后端提供RESTFul 接口,前端代码用Vue.js Bottstrap实现。 1.1 本例要求提供如下查询功能: 列表查询、单条查询 添加学生信息 更改学生信息 删…

Leetcode刷题笔记--Hot11-20

1--有效的括号(20) 主要思路: 利用栈,遍历字符串,遇到左括号则入栈,遇到右括号则出栈,并判断出栈元素是否与右括号匹配; 当字符串有效时,栈为空(所有左括号都…

怎么获得红米手机4A的Root权限

红米手机4A通过什么方式获得Root权限?大家知道,Android设备有Root权限,一旦手机获得root相关权限,可以实现更强大的功能,举个栗子大家企业的营销部门同事,使用某些营销工具都需要在Root权限下执行&#xff…

一文解决找不到电脑文件的烦恼

Everything 相信大家在累积了几年的科研数据以后,总会因为顺手将文件保存在电脑里,但是回头找的时侯,因为时间过去太久了,而找不到,给本就艰难的科研雪上加霜,十分的烦躁,可能固执起来找一个小时…

才在计算机存的东西搜索不到,解决电脑搜索不到文件的方法(很有效)

《解决电脑搜索不到文件的方法(很有效)》由会员分享,可在线阅读,更多相关《解决电脑搜索不到文件的方法(很有效)(4页珍藏版)》请在人人文库网上搜索。 1、解决电脑搜索不到文件的方法(很有效!)这几天XP系统的搜索功能搜索不到任何文件&#x…