• docker 容器中访问宿主机或者其他容器


    1. 首先可以用命令查看桥接模式下的所有网络
    docker network inspect bridge
    
    [
        {
            "Name": "bridge",
            "Id": "587fe8337798f3f26e590f9a6b8f67d98641077412924e5c7a48f088cd27f48d",
            "Created": "2020-06-28T16:07:26.189913852+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": {
                "057c865e764d2965e6bb65161d14f42956755921058e844eadb8f60e854bb5b9": {
                    "Name": "some-redmine2",
                    "EndpointID": "1fc4f99867419fd5c6cf76cba7b8d60601b1ddcb6e6ae8b97c137db21c3f76d4",
                    "MacAddress": "02:42:ac:11:00:03",
                    "IPv4Address": "172.17.0.3/16",
                    "IPv6Address": ""
                },
                "08e9b1bcc06bff2a14de1ed167fdba16a814b8fdd2fe50f83ca7b5ca92808298": {
                    "Name": "pgadmin4",
                    "EndpointID": "601b35110e30272fda12e7c8f3a2c62fe15752b7322019a1da87971c79a07ebe",
                    "MacAddress": "02:42:ac:11:00:04",
                    "IPv4Address": "172.17.0.4/16",
                    "IPv6Address": ""
                },
                "2290b60f3ac6fc6796beb5ad59838f6c8af5258d8a44213bfb0470eb03767b89": {
                    "Name": "db",
                    "EndpointID": "b69debde9c98562686bb21dc28a7df064579619dd5cf43265077ee5fc413c206",
                    "MacAddress": "02:42:ac:11:00:02",
                    "IPv4Address": "172.17.0.2/16",
                    "IPv6Address": ""
                },
                "88f3588039234bad40b020e000fe33d70265741d091fd057d95512fd0c01beb1": {
                    "Name": "odoo12-test",
                    "EndpointID": "5496fc9922090053943641c97f6ef7ed1a2811cc12666f8c89fffccdf85b9dab",
                    "MacAddress": "02:42:ac:11:00:05",
                    "IPv4Address": "172.17.0.5/16",
                    "IPv6Address": ""
                },
                "96282a47e1cd91c9f8b1ecb41eb8e92f79dcd310aefef5b0fc34aeac369031e2": {
                    "Name": "vscode",
                    "EndpointID": "e10e2bbc423ef21d5a6538656ff27a66bc4d9d1707437d41e62c992573903969",
                    "MacAddress": "02:42:ac:11:00:0a",
                    "IPv4Address": "172.17.0.10/16",
                    "IPv6Address": ""
                },
                "e39fa67e7a7e11e97b0305c9ca7c73e94c4b27bc5446414b553ad46cf6ebb1d1": {
                    "Name": "odoo14",
                    "EndpointID": "07220b6cc2ce860d6ce6781fc3409f4498df9339bd082606a00c39053966d8bd",
                    "MacAddress": "02:42:ac:11:00:07",
                    "IPv4Address": "172.17.0.7/16",
                    "IPv6Address": ""
                }
            },
            "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": {}
        }
    ]
    
    1. 可以得到的信息:
      • docker 网络名称:bridge
      • 子网掩码:172.17.0.0/16
      • 在该网段下的所有容器名称,以及对应的IP地址
    2. 在同一个网段下,容器之间的连接就畅通无阻了.
    3. 宿主机的主机号默认为1,即 172.17.0.1
  • 相关阅读:
    在线漏洞检测网站
    渗透测试工具库
    端口利用解析
    Linux安全脚本
    Linux常见系统故障
    Oracle
    Redis和MongoDB区别
    MHA在监控和故障转移时都做了什么
    Oracle 11g Dataguard参数详解
    Oracle
  • 原文地址:https://www.cnblogs.com/qianxunman/p/13976858.html
Copyright © 2020-2023  润新知