容器名称在compose中无法解析,但IP是

我在撰写模式下运行了两个容器。容器可以通过IP相互通信,但不能通过容器名称相互通信-无法解析。

Docker网络检查容器的运行位置


docker inspect mycompose
[
    {
        "Name": "mycompose","Id": "5d6f614b1a67efa38143adf745700cac103be07f74bcb219fd547aa8ce8abd1e","Created": "2019-11-07T17:08:49.940162+01:00","Scope": "local","Driver": "nat","EnableIPv6": false,"IPAM": {
            "Driver": "windows","Options": null,"Config": [
                {
                    "Subnet": "172.22.144.0/20","Gateway": "172.22.144.1"
                }
            ]
        },"Internal": false,"Attachable": true,"Ingress": false,"ConfigFrom": {
            "Network": ""
        },"ConfigOnly": false,"Containers": {
            "876efda0f26487b4c56dd52485e6f76ecc5c97214ae99cb0760a5cad4c65ea74": {
                "Name": "mycompose_brim_1","EndpointID": "15a3049b1f79d5da3129030574fd16dc46ced5246f15fe00b08b778a2b8ab8ef","MacAddress": "00:15:5d:57:23:87","IPv4Address": "172.22.144.113/16","IPv6Address": ""
            },"b8c596491ae84a1da8d597ea6ab6edf5872405856520e46d8f35581f48314b5f": {
                "Name": "mycompose_brimdb_1","EndpointID": "8bbf233cfeb57729570f581dd34f6677a6a6655dd64c2090dacc26b91604eb7c","MacAddress": "00:15:5d:57:25:be","IPv4Address": "172.25.113.185/16","IPv6Address": ""
            }
        },"Options": {
            "com.docker.network.windowsshim.hnsid": "48240B53-F49A-43B9-9A20-113C047D65A1"
        },"Labels": {
            "com.docker.compose.network": "v2","com.docker.compose.project": "mycompose","com.docker.compose.version": "1.24.1"
        }
    }
]

尝试按容器名称在另一个容器中ping一个容器:

PS C:\inetpub\wwwroot> ping mycompose_brimdb_1
Ping request could not find host mycompose_brimdb_1. Please check the name and try again

尝试按服务名称ping:

PS C:\inetpub\wwwroot> ping brimdb
Ping request could not find host brimdb. Please check the name and try again.

尝试通过IP对同一容器执行ping操作

PS C:\inetpub\wwwroot> ping 172.25.113.185

Pinging 172.25.113.185 with 32 bytes of data:
Reply from 172.25.113.185: bytes=32 time=1ms TTL=128
Reply from 172.25.113.185: bytes=32 time<1ms TTL=128
Reply from 172.25.113.185: bytes=32 time=5ms TTL=128
Reply from 172.25.113.185: bytes=32 time<1ms TTL=128

Ping statistics for 172.25.113.185:
    Packets: Sent = 4,Received = 4,Lost = 0 (0% loss),Approximate round trip times in milli-seconds:
    Minimum = 0ms,Maximum = 5ms,Average = 1ms

编写文件:

version: "3.7"

services:

  brim:
    image: brim:latest
    ports:
      - target: 50893
        published: 50893
        protocol: tcp

  brimdb:
    image: brimdb:latest
    ports:
      - target: 1555
        published: 1555
        protocol: tcp
lzdfkwdz 回答:容器名称在compose中无法解析,但IP是

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3143037.html

大家都在问