3

I am trying to add host names to host file in the windows container with no success.

According to documentation, this should add an entry on host file

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

but i can't ping "me" from the container.

Looking up at host file i find no entry for me.

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

returns only the entrys:

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

I also try to add by docker-compose file, but i am not familiar with the sintax:

Here is my docker-compose.override.yml

version: '3.4' services: trfout_wsrv: extra_hosts: - "me:127.0.1.1"

image: ${DOCKER_REGISTRY-}trfoutwsrv
build:
  context: .\TRFOUT\TRFOUT_WSRV
  dockerfile: Dockerfile
MiguelSlv
  • 14,067
  • 15
  • 102
  • 169

2 Answers2

1

seems like --add-host not supported on the window, As its says

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

I do think there is /etc/hosts in Window. Also example given in documentation is ubuntun base. docker run --add-host

Also below is the open issue on 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"
Adiii
  • 54,482
  • 7
  • 145
  • 148
  • [How can I add DNS entries to hosts file of a Windows Container?](https://stackoverflow.com/q/63880160/3110834) – Reza Aghaei Dec 28 '20 at 20:14
0

Open your C:\Windows\System32\drivers\etc\hosts and check a line as this:

192.168.xxx.xxx host.docker.internal
192.168.xxx.xxx gateway.docker.internal

if not exits, add it.

Now, you can add next flag

--add-host=host.docker.internal:host-gateway