docker --add-hostname 不适用于 windows 容器

docker --add-hostname not working for windows container

我正在尝试将主机名添加到 windows 容器中的主机文件,但没有成功。

根据文档,这应该在主机文件中添加一个条目

docker run -it --add-host me:127.0.0.1  microsoft/dotnet:nanoserver powershell

但我无法从容器中 ping "me"。

查看主机文件,我找不到适合我的条目。

cat C:\Windows\System32\drivers\etc\hosts

returns 仅条目:

192.168.125.108    host.docker.internal
192.168.125.108    gateway.docker.internal

我也尝试通过 docker-compose 文件添加,但我不熟悉语法:

这是我的docker-compose.override.yml

版本:'3.4' 服务: trfout_wsrv: extra_hosts: - "me:127.0.1.1"

image: ${DOCKER_REGISTRY-}trfoutwsrv
build:
  context: .\TRFOUT\TRFOUT_WSRV
  dockerfile: Dockerfile

似乎 --add-host 在 window 上不受支持,正如其所说

--add-host=""      : Add a line to /etc/hosts (host:IP)

我确实认为 Window 中有 /etc/hosts。文档中给出的示例还包括 ubuntun base。 docker run --add-host

下面还有 Docker Github

上的未决问题

Adding hosts for windows containers (--add-host, extra_hosts) does not work

@zachChilders The only way I managed to configure it was with echo... PowerShell would not work for some reason...

RUN echo 10.0.0.1 somehost.domain.local >> "C:\Windows\System32\drivers\etc\hosts"