Adding hosts for windows containers (--add-host, extra_hosts) does not work
Expected behavior
Either docker run --add-host argument or docker compose extra_hosts option should add host entry to etc/host for windows containers.
Actual behavior
Neither docker run --add-host argument nor docker compose extra_hosts option does add host entry to etc/host for windows containers.
Information
- Windows: Windows 10, 1709
- Docker: 17.12.0-ce-rc4
- Compose: 1.18.0
Steps to reproduce the behavior
Not working example for windows container
- Run
docker run -it --add-host me:127.0.0.1 microsoft/nanoserver - Run
ping me
Additional working example for linux container
- Run
docker run -it --add-host me:127.0.0.1 ubuntu - Run
apt-get update - Run
apt-get install iputils-ping - Run
ping me
I also see this behavior.
I also have the same problem
Same behavior confirmed.
Is not this supposed to be filed under moby/moby?
anyone has a workaround for this?
@icenold, I did the following within the Dockerfile, it has worked for my needs.
RUN $file = $Env:windir+'\System32\drivers\etc\hosts'; `
'10.0.0.1 some.host.com' | Add-Content -PassThru $file;
note that i use the back tick as my escape character.
Probably much easier just
"10.0.0.1 some.host.com" | Out-File -Append "$($Env:windir)\drivers\etc\hosts"
is there no way to do this via compose?
It's bugged out as you can see on this thread. It does not do what is expected. I beleive this shall be filed under moby/mody not docker for win.
any update/s?
I have the same issue. Any updates?
I also ran into this issue today. I seem to be unable to host map at all on microsoft/servercore, even with the above workarounds.
@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"
Not sure it helps...
any updates on this ?
It's a real pain this isn't supported. It would be really helpful to dynamically add hosts from the command line for development and staging purposes where real host names are not practical to add.
I've run into the same issue. I need to add some host entries purely for development. Works great on linux containers but we have cases where we must be able to run on Window containers as well. This seems fairly fundamental...
I have run into this issue as well and it is a platform-breaking feature in my opinion. The only option to work around this seems to be manually adding entries to the hosts file in a "RUN" directive (but this only works when building on windows!!). If I build a linux image on a linux how, any modifications I make to the hosts file inside the image using a RUN directive are ignored, which means I won't be able to use it properly when pushing and pulling it to a windows LCOW host.
EDIT: Just to be clear, I am encountering this problem both on Windows and Linux containers, I tried the reproducer @Dresel posted above with ubuntu and it doesn't work, when I try to ping me, I get ping: me: No address associated with hostname and the /etc/hosts file is completely empty.
I am running Docker CE Stable 18.06.0-ce-win72 (19098) with experimental features enabled on Windows 10 Professional.
I have run into this issue as well and it is a platform-breaking feature in my opinion. The only option to work around this seems to be manually adding entries to the hosts file in a "RUN" directive (but this only works when building on windows!!). If I build a linux image on a linux how, any modifications I make to the hosts file inside the image using a RUN directive are ignored, which means I won't be able to use it properly when pushing and pulling it to a windows LCOW host.
EDIT: Just to be clear, I am encountering this problem both on Windows and Linux containers, I tried the reproducer @Dresel posted above with ubuntu and it doesn't work, when I try to
ping me, I getping: me: No address associated with hostnameand the/etc/hostsfile is completely empty.I am running Docker CE Stable 18.06.0-ce-win72 (19098) with experimental features enabled on Windows 10 Professional.
I'm reporting the same exact issue. Any updates?
Same issue here. I think it makes sense to expedite addressing this problem.
we are facing the same issue. --add-host is not working, --network option is not supported.