我有一个简单的 Dockerfile
FROM mcr.microsoft.com/windows/servercore:1803
CMD powershell "Start-Sleep -s 100000"
和 docker-compose
定义2个服务 a
和 b
:
version: "3.5"
services:
a:
build: .
b:
build: .
networks:
default:
external: true
name: app
在 `docker-compose up --build --force-recreate` 并连接到其中一个容器后,我无法通过其服务名称解析容器:
```java
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:\>
但如果我从 docker-compose
删除 networks
部分服务名称解析工作正常 . 如果我在Linux上创建和使用桥接网络,一切都可以正常工作 .
这种行为是设计还是我做错了什么?