我有一个简单的Dockerfile
FROM mcr.microsoft.com/windows/servercore:1803
CMD powershell "Start-Sleep -s 100000"
和docker-compose
定义了两个服务a
和b
:
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上创建并使用桥接网络,那么一切也可以正常工作。
这是设计使然,还是我做错了什么?