尚硅谷Docker实战教程-笔记11【高级篇,Docker网络】

news2025/1/12 6:47:29
  • 尚硅谷大数据技术-教程-学习路线-笔记汇总表【课程资料下载】
  • 视频地址:尚硅谷Docker实战教程(docker教程天花板)_哔哩哔哩_bilibili
  1. 尚硅谷Docker实战教程-笔记01【基础篇,Docker理念简介、官网介绍、平台入门图解、平台架构图解】
  2. 尚硅谷Docker实战教程-笔记02【基础篇,Docker安装、镜像加速器配置】
  3. 尚硅谷Docker实战教程-笔记03【基础篇,Docker常用命令】
  4. 尚硅谷Docker实战教程-笔记04【基础篇,Docker镜像】
  5. 尚硅谷Docker实战教程-笔记05【基础篇,Docker本地镜像发布到阿里云与私有库】

  6. 尚硅谷Docker实战教程-笔记06【基础篇,Docker容器数据卷】

  7. 尚硅谷Docker实战教程-笔记07【基础篇,Docker常规安装简介】

  8. 尚硅谷Docker实战教程-笔记08【高级篇,Docker复杂安装详说】

  9. 尚硅谷Docker实战教程-笔记09【高级篇,DockerFile解析】

  10. 尚硅谷Docker实战教程-笔记10【高级篇,Docker微服务实战】

  11. 尚硅谷Docker实战教程-笔记11【高级篇,Docker网络】

  12. 尚硅谷Docker实战教程-笔记12【高级篇,Docker-compose容器编排】

  13. 尚硅谷Docker实战教程-笔记13【高级篇,Docker轻量级可视化工具Portainer】

  14. 尚硅谷Docker实战教程-笔记14【高级篇,Docker容器监控之CAdvisor+InfluxDB+Granfana、Docker终章总结】

目录

2.高级篇(大厂进阶)

4.Docker网络

P066【66_docker network简介】08:46

P067【67_docker network常用命令】04:17

P068【68_docker network能干嘛】03:09

P069【69_docker network网络模式有几种】03:48

P070【70_docker network底层ip和容器映射变化】06:16

P071【71_docker network之bridge】13:13

P072【72_docker network之host】08:19

P073【73_docker network之none】02:29

P074【74_docker network之container】07:15

P075【75_docker network之自定义网络上集】03:12

P076【76_docker network之自定义网络中集】03:54

P077【77_docker network之自定义网络下集】04:17


​​​​​​​2.高级篇(大厂进阶)

4.Docker网络

P066【66_docker network简介】08:46

桥接:虚拟机直接连接外部的物理网络,主机起到了网桥的作用,虚拟机可以直接访问外网,并且是透明的。

[root@node001 ~]# 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
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:45:80:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.101/24 brd 192.168.10.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::363b:8659:c323:345d/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:1c:3c:a9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:1c:3c:a9 brd ff:ff:ff:ff:ff:ff
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:ea:3c:8d:47 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
[root@node001 ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ea:3c:8d:47  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.101  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::363b:8659:c323:345d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:45:80:b6  txqueuelen 1000  (Ethernet)
        RX packets 1347  bytes 110170 (107.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1885  bytes 539241 (526.6 KiB)
        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
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 84  bytes 9492 (9.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 84  bytes 9492 (9.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:1c:3c:a9  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@node001 ~]# 

P067【67_docker network常用命令】04:17

[root@node001 ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
15e7f7fc3ef3   bridge    bridge    local
baa791142a49   host      host      local
f1c56a47c312   none      null      local
[root@node001 ~]# docker network --help

Usage:  docker network COMMAND

Manage networks

Commands:
  connect     Connect a container to a network
  create      Create a network
  disconnect  Disconnect a container from a network
  inspect     Display detailed information on one or more networks
  ls          List networks
  prune       Remove all unused networks
  rm          Remove one or more networks

Run 'docker network COMMAND --help' for more information on a command.
[root@node001 ~]# docker network create aa_network
6396717447f3bdd837e532aa3a43a4f6d119c6ab11ad82dd3283cab6ce8e1ff2
[root@node001 ~]# docker network ls
NETWORK ID     NAME         DRIVER    SCOPE
6396717447f3   aa_network   bridge    local
15e7f7fc3ef3   bridge       bridge    local
baa791142a49   host         host      local
f1c56a47c312   none         null      local
[root@node001 ~]# docker network rm aa_network
aa_network
[root@node001 ~]# docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
        "Created": "2023-07-10T10:00:47.863580701+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]
[root@node001 ~]# 

P068【68_docker network能干嘛】03:09

docker network 作用:

  • 容器间的互联和通信以及端口映射
  • 容器IP变动时候可以通过服务名直接网络通信而不受到影响

P069【69_docker network网络模式有几种】03:48

P070【70_docker network底层ip和容器映射变化】06:16

结论:docker容器内部的ip是有可能会发生改变的。

[root@node001 ~]# docker run -it --name u1 ubuntu bash
docker: Error response from daemon: Conflict. The container name "/u1" is already in use by container "191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@node001 ~]# docker run -it --name u1 ubuntu /bin/bash
docker: Error response from daemon: Conflict. The container name "/u1" is already in use by container "191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@node001 ~]# 
[root@node001 ~]# docker ps 
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@node001 ~]# docker run -it --name u2 ubuntu /bin/bash
root@a3a2d265c8d0:/# [root@node001 ~]# 
[root@node001 ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED         SIZE
centosjava8                                         1.5       0f64bc97e953   2 days ago      1.27GB
vluubuntu                                           1.2       a1ed6fe2f61e   9 days ago      118MB
node001:5000/vluubuntu                              1.2       a1ed6fe2f61e   9 days ago      118MB
ubuntu                                              1.2       7295d0d3bc7e   9 days ago      118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu   1.3       079bf1275a8a   10 days ago     185MB
atguigu/ubuntu                                      3.7       7b40f602c178   10 days ago     72.8MB
hello-world                                         <none>    9c7a54a9a43c   2 months ago    13.3kB
tomcat                                              latest    fb5657adc892   18 months ago   680MB
mysql                                               5.7       c20987f18b13   18 months ago   448MB
registry                                            latest    b8604a3fe854   20 months ago   26.2MB
ubuntu                                              latest    ba6acccedd29   21 months ago   72.8MB
hello-world                                         latest    feb5d9fea6a5   21 months ago   13.3kB
centos                                              latest    5d0da3dc9764   22 months ago   231MB
redis                                               6.0.8     16ecd2772934   2 years ago     104MB
billygoo/tomcat8-jdk8                               latest    30ef4019761d   4 years ago     523MB
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS              PORTS     NAMES
a3a2d265c8d0   ubuntu    "/bin/bash"   About a minute ago   Up About a minute             u2
[root@node001 ~]# docker start u1
u1
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
a3a2d265c8d0   ubuntu    "/bin/bash"   2 minutes ago   Up 2 minutes             u2
191b846e7af7   ubuntu    "/bin/bash"   7 days ago      Up 4 seconds             u1
[root@node001 ~]# docker inspect u1
[
    {
        "Id": "191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266",
        "Created": "2023-07-03T03:13:52.588573071Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 78941,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2023-07-10T03:01:21.625402696Z",
            "FinishedAt": "2023-07-03T03:40:14.88557386Z"
        },
        "Image": "sha256:ba6acccedd2923aee4c2acc6a23780b14ed4b8a5fa4e14e252a23b846df9b6c1",
        "ResolvConfPath": "/var/lib/docker/containers/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266/hostname",
        "HostsPath": "/var/lib/docker/containers/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266/hosts",
        "LogPath": "/var/lib/docker/containers/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266-json.log",
        "Name": "/u1",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/tmp/myHostData:/tmp/myDockerData:ro"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                25,
                159
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": true,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "label=disable"
            ],
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": null,
            "ReadonlyPaths": null
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/43f6b0e9374010860528d0c061a9174f201391e9b2d9075fc466dc87a14efcdb-init/diff:/var/lib/docker/overlay2/f9254c3773e2c54c48ab593bcd84c8af0f7b65955f4d04fc08205a994258d983/diff",
                "MergedDir": "/var/lib/docker/overlay2/43f6b0e9374010860528d0c061a9174f201391e9b2d9075fc466dc87a14efcdb/merged",
                "UpperDir": "/var/lib/docker/overlay2/43f6b0e9374010860528d0c061a9174f201391e9b2d9075fc466dc87a14efcdb/diff",
                "WorkDir": "/var/lib/docker/overlay2/43f6b0e9374010860528d0c061a9174f201391e9b2d9075fc466dc87a14efcdb/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/tmp/myHostData",
                "Destination": "/tmp/myDockerData",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "191b846e7af7",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "ubuntu",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "fc0293e83763fea837ea4177961eeb0d8d86e7ed9293fbb5c21cad3e82025451",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/fc0293e83763",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "230dae8dc1c61af9a4280253525e6443e92dbabaa675299a3cb64cc67d84eead",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
                    "EndpointID": "230dae8dc1c61af9a4280253525e6443e92dbabaa675299a3cb64cc67d84eead",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@node001 ~]# docker inspect u1 | tail -n 20
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
                    "EndpointID": "230dae8dc1c61af9a4280253525e6443e92dbabaa675299a3cb64cc67d84eead",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@node001 ~]# docker inspect u2 | tail -n 20
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
                    "EndpointID": "07dfc1689c6be633242e6c25d9ac540c38dbdfd5e418fd55b5e13b143a6745ec",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@node001 ~]# docker rm -f u2
u2
[root@node001 ~]# docker run -it --name u3 ubuntu bash
root@32e53de0224b:/# [root@node001 ~]# 
[root@node001 ~]# docker inspect u3 | tail -n 20
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
                    "EndpointID": "03f56e1422d24b8404e2bc93ef85b1f0676279d7c761d16aac7d39c30116d2cc",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@node001 ~]# docker network create bb_network
c6cc76c12f4f793e4488364a462dfaf1be40b6c58f35548e95e8a6b0b9f2cd59
[root@node001 ~]# 

P071【71_docker network之bridge】13:13

[root@node001 ~]# docker run -d -p 8081:8080 --name tomcat81 billygoo/tomcat8-jdk8
612acb85417b79180b9dda0aee5d3435a02d8f75d9017dc5c58b48f298b03330
[root@node001 ~]# docker run -d -p 8082:8080 --name tomcat82 billygoo/tomcat8-jdk8
c1c3cceb68e2e4ac43d95d8fd5173895801b61026dcfd7fb9cfc2688341b8437
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED          STATUS          PORTS                                       NAMES
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   21 seconds ago   Up 18 seconds   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   46 seconds ago   Up 44 seconds   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
22ddf65b567c   ubuntu                  "bash"              13 minutes ago   Up 13 minutes                                               u2
32e53de0224b   ubuntu                  "bash"              19 minutes ago   Up 19 minutes                                               u3
191b846e7af7   ubuntu                  "/bin/bash"         7 days ago       Up 23 minutes                                               u1
[root@node001 ~]# docker stop u1 u2 u3
u1
u2
u3
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED              STATUS              PORTS                                       NAMES
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   45 seconds ago       Up 42 seconds       0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   About a minute ago   Up About a minute   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# 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
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:45:80:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.101/24 brd 192.168.10.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::363b:8659:c323:345d/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:1c:3c:a9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:1c:3c:a9 brd ff:ff:ff:ff:ff:ff
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ea:3c:8d:47 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:eaff:fe3c:8d47/64 scope link 
       valid_lft forever preferred_lft forever
13: br-c6cc76c12f4f: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:60:73:7a:a9 brd ff:ff:ff:ff:ff:ff
    inet 172.19.0.1/16 brd 172.19.255.255 scope global br-c6cc76c12f4f
       valid_lft forever preferred_lft forever
17: veth69f6c0e@if16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default 
    link/ether 92:77:13:19:88:b9 brd ff:ff:ff:ff:ff:ff link-netnsid 3
    inet6 fe80::9077:13ff:fe19:88b9/64 scope link 
       valid_lft forever preferred_lft forever
19: vetha0b2bcb@if18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default 
    link/ether 6e:91:00:5d:6f:b6 brd ff:ff:ff:ff:ff:ff link-netnsid 4
    inet6 fe80::6c91:ff:fe5d:6fb6/64 scope link 
       valid_lft forever preferred_lft forever
[root@node001 ~]# docker exec -it tomcat81 bash
root@612acb85417b:/usr/local/tomcat# 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
16: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:05 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.5/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
root@612acb85417b:/usr/local/tomcat# read escape sequence
[root@node001 ~]# docker exec -it tomcat82 bash
root@c1c3cceb68e2:/usr/local/tomcat# 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
18: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:06 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.6/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
root@c1c3cceb68e2:/usr/local/tomcat# read escape sequence
[root@node001 ~]# 

P072【72_docker network之host】08:19

[root@node001 ~]# docker start tomcat81
tomcat81
[root@node001 ~]# docker start tomcat82
tomcat82
[root@node001 ~]# docker run -d -p 8083:8080 --network host --name tomcat83 billygoo/tomcat8-jdk8
WARNING: Published ports are discarded when using host network mode
f6336ffb274c54cb86b727195f878b559b8f6e8aa6f6fb734c75b24d7b20099c
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED         STATUS          PORTS                                       NAMES
f6336ffb274c   billygoo/tomcat8-jdk8   "catalina.sh run"   5 seconds ago   Up 3 seconds                                                tomcat83
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   4 hours ago     Up 48 seconds   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   4 hours ago     Up 52 seconds   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# docker rm -f tomcat83
tomcat83
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED       STATUS         PORTS                                       NAMES
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   4 hours ago   Up 3 minutes   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   4 hours ago   Up 3 minutes   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# docker run -d              --network host --name tomcat83 billygoo/tomcat8-jdk8
bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b
[root@node001 ~]# docker inspect tomcat83
[
    {
        "Id": "bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b",
        "Created": "2023-07-10T07:25:41.756619244Z",
        "Path": "catalina.sh",
        "Args": [
            "run"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 29365,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2023-07-10T07:25:42.079612342Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:30ef4019761d4aee397841d0b4291a928a4816745e2eba2ead83f1d2cf64d42a",
        "ResolvConfPath": "/var/lib/docker/containers/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b/hostname",
        "HostsPath": "/var/lib/docker/containers/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b/hosts",
        "LogPath": "/var/lib/docker/containers/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b-json.log",
        "Name": "/tomcat83",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "host",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                30,
                159
            ],
            "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",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "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/629599bb853e3e9eebfe87c61dd999d46cbcfc187f29505a3672afa0a75ff956-init/diff:/var/lib/docker/overlay2/9842fc8b9968299b96b9d8c1eb56096313ac3d3b50930cc7c262ff86a3d31e82/diff:/var/lib/docker/overlay2/7c4eb16163030abb5a2df0b7aac0a4047e03fad852cef52dffe3ece7f47a2c62/diff:/var/lib/docker/overlay2/534dcd05dc0c4c5ac338d39ef770a7b87ec3ad0ae4ca8f84570f28cc24cafb60/diff:/var/lib/docker/overlay2/d0fd9f89b30193ea1d8715e4a16956ad9f6b5eadcd3e3ba18bacb3f78bcc7ced/diff:/var/lib/docker/overlay2/268ce34b7cafa7ebe9d4dd9cc38d505d2c1fa43132c84c50ede21a5cc4f41981/diff:/var/lib/docker/overlay2/10ae0293114a7166a84b7c0cf5e0b1f8056bca9d819154fc78475563b9021645/diff:/var/lib/docker/overlay2/2b04040394297975a4ed6124b0886ae08427656f2a0a596ace8d6902a4756c82/diff:/var/lib/docker/overlay2/6bc48a69da1f07ee2209d121ce1fab14b8ab4dc897fb0cdd3ca9abd507f0b3b6/diff:/var/lib/docker/overlay2/4f30323fd41675a567ebd4a4484bcdd5a5fed81c92a2f96ab28bea370244800f/diff:/var/lib/docker/overlay2/d089666b37a1f0650501fdd6ecdf9971ec871dbe4b1ffde16c471aae7284154e/diff:/var/lib/docker/overlay2/464427884ca315d81c9ba390bb0a1d095599c04e12dd71e626dcd7335d0fed51/diff:/var/lib/docker/overlay2/893d0d8ac70514a6a52ab778a2c1e4f027f9a52438cdafa60953057ad06a2a84/diff:/var/lib/docker/overlay2/1f631e4437002ddab9e06016c026fdece3744a3817284da253433724050ddeff/diff",
                "MergedDir": "/var/lib/docker/overlay2/629599bb853e3e9eebfe87c61dd999d46cbcfc187f29505a3672afa0a75ff956/merged",
                "UpperDir": "/var/lib/docker/overlay2/629599bb853e3e9eebfe87c61dd999d46cbcfc187f29505a3672afa0a75ff956/diff",
                "WorkDir": "/var/lib/docker/overlay2/629599bb853e3e9eebfe87c61dd999d46cbcfc187f29505a3672afa0a75ff956/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "node001",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "8080/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64",
                "JAVA_VERSION=8u171",
                "JAVA_DEBIAN_VERSION=8u171-b11-1~deb9u1",
                "CA_CERTIFICATES_JAVA_VERSION=20170531+nmu1",
                "CATALINA_HOME=/usr/local/tomcat",
                "TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib",
                "LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib",
                "OPENSSL_VERSION=1.1.0f-3+deb9u2",
                "GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23",
                "TOMCAT_MAJOR=8",
                "TOMCAT_VERSION=8.0.53",
                "TOMCAT_SHA512=cd8a4e48a629a2f2bb4ce6b101ebcce41da52b506064396ec1b2915c0b0d8d82123091242f2929a649bcd8b65ecf6cd1ab9c7d90ac0e261821097ab6fbe22df9",
                "TOMCAT_TGZ_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://www.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz",
                "TOMCAT_ASC_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://www.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc"
            ],
            "Cmd": [
                "catalina.sh",
                "run"
            ],
            "Image": "billygoo/tomcat8-jdk8",
            "Volumes": null,
            "WorkingDir": "/usr/local/tomcat",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "7591a0130844df2007694034069cfaf3fa79bc78231b9ae9009018da96a5531e",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/default",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "host": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "baa791142a49a66e391e60263e60a188bdc7e27072119fd585436e281d91160f",
                    "EndpointID": "cbbf729509f1984fc3eb556ad34d37f17915d0cd41d1a47ebad5326637ff3583",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@node001 ~]# docker exec -it tomcat83 bash
root@node001:/usr/local/tomcat# 

P073【73_docker network之none】02:29

[root@node001 ~]# docker run -d -p 8084:8080 --network none --name tomcat84 billygoo/tomcat8-jdk8
6f3e8c545791a435a9b3dbcd8ec1c0fb051daa386ea4e3513e775c1623d95046
[root@node001 ~]# docker inspect tomcat84 | tail -n 20
            "Networks": {
                "none": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "f1c56a47c3128e398257a61ffa51451a2532f7dbe34336a5169e4a16f770f0a2",
                    "EndpointID": "ca7ed125ec6466a372ea3dc9c5d00b0b5d99a1680966e0830f19a3b187606cc8",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED          STATUS          PORTS                                       NAMES
6f3e8c545791   billygoo/tomcat8-jdk8   "catalina.sh run"   12 minutes ago   Up 12 minutes                                               tomcat84
bf2b920ad4d5   billygoo/tomcat8-jdk8   "catalina.sh run"   31 minutes ago   Up 31 minutes                                               tomcat83
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago      Up 35 minutes   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago      Up 36 minutes   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# docker exec -it tomcat84 bash
root@6f3e8c545791:/usr/local/tomcat# 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
root@6f3e8c545791:/usr/local/tomcat# read escape sequence
[root@node001 ~]# 

P074【74_docker network之container】07:15

container⽹络模式 

新建的容器和已经存在的一个容器共享一个网络ip配置而不是和宿主机共享。新创建的容器不会创建自己的网卡,配置自己的IP,而是和一个指定的容器共享IP、端口范围等。同样,两个容器除了网络方面,其他的如文件系统、进程列表等还是隔离的。

[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED          STATUS          PORTS                                       NAMES
6f3e8c545791   billygoo/tomcat8-jdk8   "catalina.sh run"   18 minutes ago   Up 18 minutes                                               tomcat84
bf2b920ad4d5   billygoo/tomcat8-jdk8   "catalina.sh run"   37 minutes ago   Up 37 minutes                                               tomcat83
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago      Up 41 minutes   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago      Up 41 minutes   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# docker run -d -p 8085:8080                                     --name tomcat85 billygoo/tomcat8-jdk8
439b7efdb024b4b359a4a33f31620c01128828923813b5669d233172d8602965
[root@node001 ~]# docker run -d -p 8086:8080 --network container:tomcat85 --name tomcat86 billygoo/tomcat8-jdk8
docker: Error response from daemon: conflicting options: port publishing and the container type network mode.
See 'docker run --help'.
[root@node001 ~]# docker rm -f tomcat85
tomcat85
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED          STATUS          PORTS                                       NAMES
6f3e8c545791   billygoo/tomcat8-jdk8   "catalina.sh run"   21 minutes ago   Up 21 minutes                                               tomcat84
bf2b920ad4d5   billygoo/tomcat8-jdk8   "catalina.sh run"   41 minutes ago   Up 41 minutes                                               tomcat83
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago      Up 45 minutes   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago      Up 45 minutes   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# docker run -it                                                    --name alpine1 alpine /bin/sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
59bf1c3509f3: Pull complete 
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Downloaded newer image for alpine:latest
/ # ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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
13: eth0@if14: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
/ # exit
[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED          STATUS             PORTS                                       NAMES
64ffeaad19d9   alpine                  "/bin/sh"           15 minutes ago   Up 15 minutes                                                  alpine2
6f3e8c545791   billygoo/tomcat8-jdk8   "catalina.sh run"   40 minutes ago   Up 40 minutes                                                  tomcat84
bf2b920ad4d5   billygoo/tomcat8-jdk8   "catalina.sh run"   59 minutes ago   Up 59 minutes                                                  tomcat83
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago      Up About an hour   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago      Up About an hour   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# 

[root@node001 ~]# docker run -it --network container:alpine1 --name alpine2  alpine /bin/sh
/ # ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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
13: eth0@if14: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
/ # exit
[root@node001 ~]# 

P075【75_docker network之自定义网络上集】03:12

[root@node001 ~]# docker network ls
NETWORK ID     NAME         DRIVER    SCOPE
c6cc76c12f4f   bb_network   bridge    local
616bcbc5cc80   bridge       bridge    local
baa791142a49   host         host      local
f1c56a47c312   none         null      local
[root@node001 ~]# docker ps 
CONTAINER ID   IMAGE                   COMMAND             CREATED             STATUS             PORTS                                       NAMES
6f3e8c545791   billygoo/tomcat8-jdk8   "catalina.sh run"   48 minutes ago      Up 48 minutes                                                  tomcat84
bf2b920ad4d5   billygoo/tomcat8-jdk8   "catalina.sh run"   About an hour ago   Up About an hour                                               tomcat83
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago         Up About an hour   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago         Up About an hour   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# 

P076【76_docker network之自定义网络中集】03:54

[root@node001 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND             CREATED             STATUS             PORTS                                       NAMES
6f3e8c545791   billygoo/tomcat8-jdk8   "catalina.sh run"   58 minutes ago      Up 58 minutes                                                  tomcat84
bf2b920ad4d5   billygoo/tomcat8-jdk8   "catalina.sh run"   About an hour ago   Up About an hour                                               tomcat83
c1c3cceb68e2   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago         Up About an hour   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp   tomcat82
612acb85417b   billygoo/tomcat8-jdk8   "catalina.sh run"   5 hours ago         Up About an hour   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   tomcat81
[root@node001 ~]# docker exec -it tomcat81 bash
root@612acb85417b:/usr/local/tomcat# 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
7: eth0@if8: <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
root@612acb85417b:/usr/local/tomcat# ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.591 ms
64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.099 ms
[root@node001 ~]# docker exec -it tomcat82 bash
root@c1c3cceb68e2:/usr/local/tomcat# 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
9: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
root@c1c3cceb68e2:/usr/local/tomcat# 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.708 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.136 ms
64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.095 ms

P077【77_docker network之自定义网络下集】04:17

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/739981.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

盛格塾暑期公益课程《学活LINUX》

学习LINUX有很多种方法&#xff0c;本系列课程以动手试验为主&#xff0c;取一个活的LINUX系统&#xff08;GDK8&#xff09;作为目标&#xff0c;使用内核调试器&#xff08;挥码枪&#xff09;将其中断到调试器&#xff0c;在调试器的帮助下&#xff0c;观察调用过程、执行现…

【1++的Linux】之基础开发工具

&#x1f44d;作者主页&#xff1a;进击的1 &#x1f929; 专栏链接&#xff1a;【1的Linux】 文章目录 一&#xff0c;Linux软件包管理管理器二&#xff0c;Linux编辑器--vim2.1 什么是vim2.2 vim的基本操作 三&#xff0c;gcc的使用四&#xff0c;gdb的使用五&#xff0c;项目…

课时7:Trustzone基础知识

快速链接: . 👉👉👉 个人博客笔记导读目录(全部) 👈👈👈 付费专栏-付费课程 【购买须知】:Secureboot从入门到精通-[目录] 👈👈👈目录 Trustzone安全扩展双系统架构Trustone架构多方位支持的安全

探索Gradio库中的Textbox模块及其强大功能

❤️觉得内容不错的话&#xff0c;欢迎点赞收藏加关注&#x1f60a;&#x1f60a;&#x1f60a;&#xff0c;后续会继续输入更多优质内容❤️ &#x1f449;有问题欢迎大家加关注私戳或者评论&#xff08;包括但不限于NLP算法相关&#xff0c;linux学习相关&#xff0c;读研读博…

作用域、垃圾回收机制、闭包、构造函数

作用域 作用域规定了变量能够被访问的 ‘范围’&#xff0c;离开了这个范围变量便不能被访问 分为&#xff1a; 局部作用域 函数作用域块级作用域 let/const 全局作用域 作用域链 嵌套关系的作用域串联起来形成了作用域链 作用:作用域链本质上是底层的变量的查找机制 函…

简写MKL库windows安装以及python如何调用dll库

MKL安装: 最新MKL库下载地址 Donwload: Accelerate Fast Math with Intel oneAPI Math Kernel Library 64位以及32位我直接都安装了 之后配置各种包含目录以及环境变量&#xff1a;网上有很多配置vs的配置教程&#xff0c;这里就不贴了。 &#xff08;ps: 2023 在vs2019上&a…

nodejs高级编程-核心模块

一、path 1 获取路径中的基础名称 const path require(path)// console.log(__filename) // /Users/liuchongyang/Desktop/分享/网页读取本地文件/node.js// 1 获取路径中的基础名称 /*** 01 返回的就是接收路径当中的最后一部分 * 02 第二个参数表示扩展名&#xff0c;如果…

手把手教-单片机stm32基于w25q128使用文件系统

一、开发测试环境 ①野火stm32f407开发板 ②rtthread操作系统 W25Q128的电路原理图&#xff1a; 二、开发步骤 ①使能spi驱动。 ②使能spi bus/device 驱动&#xff0c;选择sfud驱动。 ③开启dfs功能&#xff0c;选择elm文件系统。 ④保存&#xff0c;重新生成工程。 ⑤下载到…

VueCli 脚手架使用

VueCli 脚手架 到目前为止&#xff0c;已经会了Vue基本使用&#xff08;去创建vue实例&#xff0c;创建之后再去挂载&#xff0c;挂载之后就去使用各种功能&#xff0c;挂载之后就可以使用其各种功能&#xff0c;data methods compute 以及各个生命周期&#xff0c;常用的属性以…

779. 最长公共字符串后缀

题面&#xff1a; 给出若干个字符串&#xff0c;输出这些字符串的最长公共后缀。 输入格式 由若干组输入组成。 每组输入的第一行是一个整数 NN。 NN 为 00 时表示输入结束&#xff0c;否则后面会继续有 NN 行输入&#xff0c;每行是一个字符串&#xff08;字符串内不含空白符&…

Redis深入 —— 持久化和事务

前言 最近的学习中&#xff0c;荔枝深入了解了Redis的持久化、Redis事务相关的知识点并整理相应的学习笔记&#xff0c;在这篇文章中荔枝也主要梳理了相应的笔记和基本知识&#xff0c;小伙伴们如果需要的话可以看看哈。 文章目录 前言 一、Redis持久化 1.1 RDB 1.1.1 Redi…

掌握驱动之道:L298N模块多方式驱动电机的优劣分析

L298N模块是一种常用的直流电机驱动模块&#xff0c;它可以通过控制输入端口来实现对电机的速度和方向的控制。L298N模块有3个输入端口&#xff1a;IN1、IN2和EN。 方法一&#xff1a;使用高级定时器输出通道和互补输出通道控制电机 将模块的IN1和IN2分别连接到STM32高级定时器…

Python GUI编程利器:Tkinker中的事件处理(11)

​ 小朋友们好&#xff0c;大朋友们好&#xff01; 我是猫妹&#xff0c;一名爱上Python编程的小学生。 和猫妹学Python&#xff0c;一起趣味学编程。 今日目标 学习下事件处理的相关知识点&#xff1a; 事件处理四要素 事件序列 事件绑定 今天要实现如下效果&#xff1…

Java在Excel中进行数据分析

摘要&#xff1a;本文由葡萄城技术团队于CSDN原创并首发。转载请注明出处&#xff1a;葡萄城官网&#xff0c;葡萄城为开发者提供专业的开发工具、解决方案和服务&#xff0c;赋能开发者。 前一段时间淘宝出了一个“淘宝人生”的模块&#xff0c;可以看从注册淘宝账号至今的消…

k8s实战3-使用Helm在AKS上发布应用

AKS(Azure Kubenetes Service)是微软云azure上的K8s服务。 主要分为三步 1 连接到AKS 2 用kubectl发布应用 3 用Helm发布应用 1 登录 az login 2 连接dp-npr-dsm-aks&#xff08;Dsm项目的AKS&#xff09; az account set --subscription {{subID}} az aks get-credent…

指针的进阶(一)

目录 1. 字符指针 方法一 方法二 字符指针面试题 2. 指针数组 3. 数组指针 3.1 数组指针的定义 3.2 &数组名VS数组名 3.3 数组指针的使用 4. 数组传参和指针传参 4.1 一维数组传参 4.2 二维数组传参 4.3 一级指针传参 4.4 二级指针传参 5. 函数指针 代码一 代…

Windows用户怎么取消访问共享文件夹的密码

许多Windows系统用户在访问共享文件夹的时候却提示需要输入密码才可访问。这一步给很多人造成了困扰&#xff0c;其实我们可以取消访问共享文件夹密码。请看下面的两个方法。 方法一&#xff1a; 搜索 网络和共享中心。点击 更改高级共享设置。在最底下密码保护的共享那项&…

用C#写汉诺塔问题

假设要将n个圆盘从A->C&#xff0c;中间可以借助B&#xff0c;那么递归思路是这样的&#xff0c;我们先将除最大的一个圆盘外的其它n-1个圆盘从A->B,借助C&#xff0c;然后将最大的一个圆盘搬到C&#xff0c;最后将刚才的n-1个盘子&#xff0c;从B->C借助A&#xff0c…

Qt完成闹钟提示

未启动: 启动&#xff1a; .cpp #include "widget.h" #include "ui_widget.h"void Widget::btn1_slots() {//点击启动开始定时event_timer this->startTimer(1000);btn1->setEnabled(false);btn2->setEnabled(true);edit2->setEnabled(false…

一个月学通Python(十三):高级Python必须掌握的进阶知识点

专栏介绍 结合自身经验和内部资料总结的Python教程,每天3章,1个月就能全方位的完成Python的学习并进行实战开发。加油吧!卷起来! 全部文章请访问专栏:《Python全栈教程(0基础》 文章目录 专栏介绍Python语言进阶1. 数据结构和算法2. 函数的使用方式3. 面向对象相关知识…