如果使用用户定义的网络,Windows容器不会按服务名称解析容器

时间:2018-12-08 19:34:49

标签: docker docker-for-windows

我有一个简单的Dockerfile

FROM mcr.microsoft.com/windows/servercore:1803
CMD powershell "Start-Sleep -s 100000"

docker-compose定义了两个服务ab

version: "3.5"
    services:
        a:
           build: .
        b:
           build: .

 networks:
     default:
         external: true
         name: app

```

docker-compose up --build --force-recreate并连接到一个容器之后,我无法通过其服务名称来解析容器:

PS C:\> ping a
Ping request could not find host a. Please check the name and try again.
PS C:\> ping b
Ping request could not find host b. Please check the name and try again.
PS C:\> Resolve-DnsName a
Resolve-DnsName : a : The filename, directory name, or volume label syntax is incorrect
At line:1 char:1
+ Resolve-DnsName a
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (a:String) [Resolve-DnsName], Win32Exception
    + FullyQualifiedErrorId : ERROR_INVALID_NAME,Microsoft.DnsClient.Commands.ResolveDnsName

PS C:\> Resolve-DnsName b
Resolve-DnsName : b : The filename, directory name, or volume label syntax is incorrect
At line:1 char:1
+ Resolve-DnsName b
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (b:String) [Resolve-DnsName], Win32Exception
    + FullyQualifiedErrorId : ERROR_INVALID_NAME,Microsoft.DnsClient.Commands.ResolveDnsName

PS C:\>

但是,如果我从networks中删除docker-compose部分,则服务名称解析会很好。如果我在Linux上创建并使用桥接网络,那么一切也可以正常工作。

这是设计使然,还是我做错了什么?

0 个答案:

没有答案